You are not using mysql_query correctly.  You need to fetch results from 
the query and output the results to your DataTable.

$row = mysql_fetch_assoc($yes);
$countYes = $row['YesOrNo'];
$row = mysql_fetch_assoc($no);
$countNo = $row['YesOrNo'];
//...
var data = google.visualization.arrayToDataTable([
    ['YesOrNo', 'Mount'],
    ['Yes', <?php echo $countYes; ?>],
    ['No', <?php echo $countNo; ?>]
]);

Also, if you are fetching data from a single table, you don't need to use 
two separate queries, you can combine them into one (the structure of the 
query depends on how your table is laid out, I can help you figure it out 
if you want).

On Thursday, January 16, 2014 9:37:14 AM UTC-5, r1chynet wrote:
>
> Hi,
>
> how can I connect the Google Pie Chart with a MySQL database?
>
> My following code doesn't work :-(
>
> <?php
> $con=mysqli_connect("localhost","User","Password,"testdb");
> if (mysqli_connect_errno())
>   {
>   echo "Failed to connect to MySQL: " . mysqli_connect_error();
>   }
> $sql = 'SELECT COUNT(*)-SUM(testcolumn) AS 'YesOrNo' FROM testtable';
> $yes = mysql_query ( $sql );
> $sql = 'SELECT COUNT(*)-SUM(testcolumn) AS 'YesOrNo' FROM testtable';
> $no = mysql_query ( $sql );
> ?>
> <html>
>   <head>
>     <script type="text/javascript" src="https://www.google.com/jsapi
> "></script>
>     <script type="text/javascript">
>       google.load("visualization", "1", {packages:["corechart"]});
>       google.setOnLoadCallback(drawChart);
>       function drawChart() {
>         var data = google.visualization.arrayToDataTable([
>           ['YesOrNo', 'Mount'],
>           ['Yes', $yes],
>           ['No',    $no]
>         ]);
>
>         var options = {
>           title: 'Test Pie Chart',
>           is3D: true,
>         };
>
>         var chart = new 
> google.visualization.PieChart(document.getElementById('piechart_3d'));
>         chart.draw(data, options);
>       }
>     </script>
>   </head>
>   <body>
>     <div id="piechart_3d" style="width: 900px; height: 500px;"></div>
>   </body>
> </html>
>
> Thanks for helping!
>

-- 
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.

Reply via email to