0

Following on from this thread: Accessing MySQL database - D3

Can anyone help with a parse error I'm getting? There seems to be conflicting information out there about what can cause this?

Parse error:

Error: Problem parsing d="M30,NaNL34,NaNL38,NaNL42,NaNL46,NaNL50,NaNL54,NaNL58.......

getdata.php:

    <?php
    $username="*****"; 
    $password="*****";   
    $host="********";
    $link=mysql_connect($host,$username,$password)
    or die("Unable to connect to MySQL");

    mysql_select_db("*****", $link) or die( "Unable to select database"
    .mysql_error());

    $res = mysql_query("SELECT * FROM TestSourceSampleData")
    or die ("Unable to run query");
    $data = array();

    while ($row = mysql_fetch_assoc($res))
    {  
    $data[] = array("reading" => $row['reading']);
    } 
    echo json_encode($data);     
    mysql_close($link);
    ?>

Output from getdata.php:

[{"reading":"10"},{"reading":"10.2"},{"reading":"10.3"},{"reading":"10.3"}........

..when print json file:

    Array[120]
    [0 … 99]
    0: Object
    reading: "10"
    __proto__: Object
    1: Object
    reading: "10.2"
    __proto__: Object
    2: Object
    reading: "10.3"
    __proto__: Object
    3: Object
    4: Object
    5: Object

http://bl.ocks.org/5fc4cd5f41a6ddf2df23

3
  • it's not clear where the parsing code is - if this is where the error is, best to post the code where the JSON is fed in and parsed. The "printing json file" bit look like a copy-paste from a javascript console - if you're looking to dump that info, you might try JSON.stringify() to get clearer output. Commented Dec 9, 2012 at 23:44
  • Thanks - was a copy-paste! I'll use the stringify method from now on. The link to the code is at the bottom of the post above . First encounter with this so unsure how to go about parsing the JSON? Commented Dec 9, 2012 at 23:59
  • oops, I didn't catch the parsing code in the external link. Commented Dec 10, 2012 at 0:31

1 Answer 1

1

In your block you use:

var data = jsondata.map(function(d) { return d.Value; });

while in your question you mention that the name of the key is reading, which would mean your code should look like:

var data = jsondata.map(function(d) { return d.reading; });
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - should have realised that myself. Working perfectly now:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.