title: Using Google Chart with PHP MYSQL
body: <p>I have to show how many accounts and balance 1 user has. I have to show the data on a table and a pie chart. I have created a Pie Chart from Google Chart. However, I got stuck on inserting the data for the pie chart using PHP. Please help! :(</p>
  
  <pre><code> &lt;tr&gt;
                          &lt;th&gt;Account Type&lt;/th&gt;
                          &lt;th&gt;Account Number&lt;/th&gt;
                          &lt;th&gt;Account Balance&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                      &lt;?php
                      $query = "SELECT * FROM account WHERE user_id='$user_id'";
                      $result = mysqli_query($link, $query) or die(mysqli_error($link));
                      while ($row = mysqli_fetch_array($result)) {
                          $acc_type = $row ['account_type'];
                          $acc_num = $row ['account_number'];  
                          $acc_bal = $row ['account_balance']; 
  
                          ?&gt;
                      &lt;tbody&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;?php echo $acc_type ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $acc_num ?&gt;&lt;/td&gt;
                              &lt;td&gt;S$ &lt;?php echo $acc_bal ?&gt;&lt;/td&gt;
                          &lt;?php
                      }
  
  
                      ?&gt; 
                          &lt;/tr&gt;
                  &lt;/tbody&gt;  
                  &lt;tr class="alt"&gt;
                      &lt;?php 
                      $query = "SELECT SUM(account_balance) AS account_total FROM account WHERE user_id='$user_id'";
                      $result = mysqli_query($link, $query) or die(mysqli_error($link));
                      while ($row = mysqli_fetch_array($result)){
                          $acc_total = $row ['account_total'];
                      ?&gt;
                      &lt;td colspan="2" align="right"&gt;&lt;b&gt;Total: &lt;/b&gt;&lt;/td&gt;
                      &lt;td align="right"&gt;&lt;b&gt;S$ &lt;?php echo $acc_total ?&gt; &lt;/b&gt;&lt;/td&gt;
                      &lt;?php
                      }
                      ?&gt;
  
                  &lt;/tr&gt;  
              &lt;/table&gt;
  
                  &lt;/center&gt;
  
      // creating pie Chart
                      &lt;!--Load the AJAX API--&gt;
          &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
  
            // Load the Visualization API and the piechart package.
            google.load('visualization', '1.0', {'packages':['corechart']});
  
            // Set a callback to run when the Google Visualization API is loaded.
            google.setOnLoadCallback(drawChart);
  
            // Callback that creates and populates a data table,
            // instantiates the pie chart, passes in the data and
            // draws it.
            function drawChart() {
  
              // Create the data table. (and I think this is where I go wrong)
              var data = new google.visualization.DataTable();
              data.addColumn('string', 'Accounts');
              data.addColumn('number', 'Balance');
              data.addRows([
  
                 ['&lt;?php echo $acc_type; ?&gt;', &lt;?php echo $acc_bal; ?&gt;],
                 ['&lt;?php echo $acc_type; ?&gt;', &lt;?php echo $acc_bal; ?&gt;],   
              ]);
  
              // Set chart options
              var options = {'title':'Account Balance',
                             'width':400,
                             'height':300};
  
              // Instantiate and draw our chart, passing in some options.
              var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
              chart.draw(data, options);
            }
          &lt;/script&gt;
  
          &lt;!--Div that will hold the pie chart--&gt;
          &lt;div id="chart_div"&gt;&lt;/div&gt;
  </code></pre>