json - Creating Pie char from mysql database using php and google charts -


i trying create pie char database table.

temp -> columns(id, sent, pcount, ncount) 

pcount , ncount int numbers. want create pie chart 2 values.

i trying load file.

<html> <head>  <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); google.setonloadcallback(drawchart);  function drawchart()  {     var jsondata = $.ajax({         url: "graphdata.php",         datatype:"json",         async: false }).responsetext;  // create our data table out of json data loaded server. var data = new google.visualization.datatable(jsondata);  var options = {'title':'ticket sales', 'width':500,     'height':400};  // instantiate , draw our chart, passing in options. var chart = new google.visualization.columnchart(document.getelementbyid('chart_div')); chart.draw(data,options);  } </script> </head>  <body>     <!--div hold pie chart-->     <div id="chart_div"></div> </body>   </html> 

graphdata.php content following.

<?php  $con = mysqli_connect('127.0.0.1:3306', 'root', 'root', 'test'); if (mysqli_connect_errno()) {     echo "failed connect mysql: ".mysqli_connect_error(); }  $sql = "select pcount,count(*) count temp";  if ($result=mysqli_query($con,$sql)) {     $rownum=mysqli_num_rows($result);     printf("result set has %d rows.\n",$rownum);     mysqli_free_result($result); }  //start json data in format google chart js/api expects receieve $data = array('cols' => array(array('label' => 'pcount', 'type' => 'int'),                               array('label' => 'mcount', 'type' => 'int')),               'rows' => array());  while($row = mysqli_fetch_row($result)) {     $data['rows'][] = array('c' => array(array('v' => $row[0]), array('v' => $row[1]))); }      echo json_encode($data); ?> 

i have taken code web , modified per need. when load first php page, shows nothing. doing wrong?

i have taken code web , modified per need. when load first php page, shows nothing. doing wrong?

you have modified script wrongly , not needs. otherwise wouldn't asking you're doing wrong.

as asking "what doing wrong?" implies not understand code incl. modifications, first thing need step last working version of code.

so commit changes , diff script last working commit. show changes , it's more easier spot part introduced error.


Comments