I am trying to get my JSON encoded array formatted properly. Here is my PHP MySQL Query:
$query = "SELECT date, value1, value2
FROM testdata
ORDER BY date ASC";
$result = mysql_query($query);
$myChartData = array();
while($row = mysql_fetch_assoc($result)){
$myChartData[] = $row;
}
<script type="text/javascript">
var chartData = <?php echo json_encode($myChartData); ?>;
From the console, the object looks like this:
[Object { date="2011-02-23", value1="133034", value2="12105.78"},
Object { date="2011-02-24", value1="122290", value2="12068.50"},
Object { date="2011-03-08", value1="453142", value2="12214.38"}]
The quotation marks around the date stays, but the ones on value1 and value2 need to be stripped out.
Self-teaching noob at all of this...Thanks for your help!
value1
andvalue2
to numbers before you JSON encode. – Dan D. May 2 '12 at 20:46json_encode($myChartData)
creates JSON. And JSON is not JavaScript. It is format that was inspired by JavaScript's object literal syntax. That's all. – Felix Kling May 2 '12 at 20:48