title: Dynamic Google Line Charts
body: <p>I need to draw a line chart using "Google Charts" dynamically from MYSQLI database. I'm fetching the data required for the line chart from the MYSQLI database. </p>
  
  <p>On X-axis, I want weeks and on Y-axis, I want user id's like 0, 200, 400, 600 -----2000.</p>
  
  <p>Here is the code I implemented, Could anyone guide me where I was going wrong.</p>
  
  <pre><code>&lt;?php
  
    $DB_NAME = 'chart'; 
    $DB_HOST = 'localhost'; 
    $DB_USER = 'root';
    $DB_PASS = '';
  
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  
    if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
    }
  
    $sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(timemodified),'%d-%m-%Y') AS 'dat', userid FROM user_reg";
    $r = mysqli_query($sql) or die(mysqli_error()); 
    $transactions = array();
  
    while($result  = mysqli_fetch_assoc($r, MYSQL_ASSOC))
    {
        $transactions[] = $result;
    } 
  
    $rows = array();
    $flag = true;
    $table = array();
    $table['cols'] = array( 
  
      array('label' =&gt; 'dat', 'type' =&gt; 'string'),
      array('label' =&gt; 'userid', 'type' =&gt; 'number') );
  
    $rows = array();
  
    foreach($transactions as $tr) 
    {
       $temp = array();
       foreach($tr as $key=&gt;$value)
       {
          $temp[] = array('v' =&gt; $value); 
          $temp[] = array('v' =&gt; $value);     
       }
       $rows[] = array('c' =&gt; $temp); 
    } 
  
    $table['rows'] = $rows;
  
    $jsonTable = json_encode($table);
    echo $jsonTable.'&lt;br&gt;';
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
      &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
  
       google.load('visualization', '1', {'packages':['corechart']});
  
       google.setOnLoadCallback(drawChart);
  
      function drawChart() {
  
        var data = new google.visualization.DataTable(&lt;?=$jsonTable?&gt;);
            var options = {
            title: 'Statistics',
            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.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;!--this is the div that will hold the pie chart--&gt;
      &lt;div id="chart_div"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>