Thank you for your help, this is the code I have inside the json.php the
connection to database is done in a separate file, I don't get the JSON
objects when I call this file in the ajax script.
<?php
$selectQuery = 'SELECT * FROM competitive_daily_volume';
$result = mysql_query($selectQuery);
$rows = array();
if($result){
while($row = mysql_fetch_assoc($result)){
$temp = array();
$temp[] = array("v"=> $row['Date']);
$temp[] = array("v"=> $row['UserId']);
$temp[] = array("v"=> $row['CementBrand']);
$temp[] = array("v"=> $row['VolumeBGLP']);
$temp[] = array("v"=> $row['Type']);
$rows[] = array("c"=> $temp);
}
}
$table = array();
$table['cols'] = array(
array("id"=>"A","label"=>"Date","type"=>"string"),
array("id"=>"B","label"=>"User","type"=>"string"),
array("id"=>"C","label"=>"Cement Brand","type"=>"string"),
array("id"=>"D","label"=>"Volume","type"=>"string"),
array("id"=>"E","label"=>"Type","type"=>"string")
);
$table['rows'] = $rows;
$jsonObj = json_encode($table);
echo $jsonObj;
?>
On 12 August 2013 23:24, asgallant <[email protected]> wrote:
> I don't get that error when I use your JSON:
> http://jsfiddle.net/asgallant/R8tA9/. Can you post an example script
> (preferably on jsfiddle, you can use the example I linked to as a starting
> point) that replicates the issue?
>
>
> On Monday, August 12, 2013 3:19:07 PM UTC-4, Razee Hussein-Jamal wrote:
>
>>
>> I am trying to view my JSON string I receive from a database and view it
>> in google tables, however I receive this error: Invalid JSON string:
>> error: 1046
>>
>> In viewTable.php a part of the script is :
>>
>> function drawVisualization() {
>>
>> var jsonData = $.ajax({
>> url: "json.php", // make this url point to the data file
>> dataType: "json",
>> async: false
>> }).responseText;
>> var data = new google.visualization.**DataTable(jsonData);
>>
>> visualization = new google.visualization.Table(**
>> document.getElementById('**table'));
>> visualization.draw(data, null);
>>
>> }
>>
>> in json.php file : I query data from database and encode it to JSON
>> string which I then echo $jsonString,
>>
>> An example of JSON string output :
>>
>>
>> {"cols":
>> [{"id":"A","label":"Date","**type":"string"},{"id":"B","**
>> label":"User","type":"string"}**,{"id":"C","label":"Cement
>> Brand","type":"string"},{"id":**"D","label":"Volume","type":"**
>> string"},{"id":"E","label":"**Type","type":"string"}],
>>
>> "rows":
>> [{"c":[{"v":"08-06-2013"},{"v"**:"[email protected]"},{"v":"**
>> Muthana"},{"v":"27"},{"v":"**Local Plant"}]}]
>>
>> }
>>
>>
>> I would really appreciate any help with this problem as I can't find the
>> reason for this invalid JSON string as it seems to be correct. Thank you
>>
>>
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Google Visualization API" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-visualization-api/_4eMVS6Hdnk/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to
> [email protected].
> Visit this group at
> http://groups.google.com/group/google-visualization-api.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
Razee Hussein-Jamal
Masters in Embedded Systems,
Department of Information Technology,
Uppsala University - Sweden
Mobile Phone : +46764158553 (Sweden) , +9647701524721 (N.Iraq),
+905058622477 (Turkey)
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.