google chart + php + mysql

modified on August 2014 GOOGLE CHART + PHP + MYSQL create Infograph with Gchart..

Please my subscribe my chanel


Youtube Tutorial Link

Pray for Gaza

table gaza palestina

<?php $con=mysql_connect("localhost","root","") or die("Failed to connect with database!!!!"); mysql_select_db("gaza", $con); $sth = mysql_query("SELECT * FROM death_rate"); $rows = array(); //flag is not needed $flag = true; $table = array(); $table['cols'] = array( // Labels for your chart, these represent the column titles // Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title array('label' => 'people', 'type' => 'string'),
    array('label' => 'total', 'type' => 'number')


$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $temp = array();
    // the following line will be used to slice the Pie chart
    $temp[] = array('v' => (string) $r['people']); 

    // Values of each slice
    $temp[] = array('v' => (int) $r['total']);
    $rows[] = array('c' => $temp);

$table['rows'] = $rows;
$jsonTable = json_encode($table);
//echo $jsonTable;

    <!--Load the Ajax API-->
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">

    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(<?=$jsonTable?>);
      var options = {
           title: ' Israel genocide in Gaza. ',
          is3D: 'true',
          width: 800,
          height: 600
      // Instantiate and draw our chart, passing in some options.
      // Do not forget to check your div ID
      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, options);

    <!--this is the div that will hold the pie chart-->

<div id="chart_div"></div>


column gaza

   var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));

create infographic recent news for human solidarity still boycott israel products.

google geo chart

let’s see Google Geo chart Tutorial



35 thoughts on “google chart + php + mysql

  1. I am getting mysql_select_db() expects parameter 2 to be resource, and I am also getting mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in….. Can anyone help ?

  2. If suppose in the people field there are two women with different total value and I want only single women with total sum value of both women records to be show up in pie chart. How could I code to get such result?

  3. how can we load multiple google charts using the json_encode. I am only getting the last json_encode to be passed to the javascript.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s