Google Chart仅显示mysql数据库条目的最后日期

时间:2017-10-18 19:01:30

标签: php mysql charts google-chartwrapper

我的代码只显示我数据库的最后一个条目。 我不知道为什么。

请帮我一点。

这是我的代码:     

$hostname = "localhost";
$username = "waru";
$password = "olairhead154";
$database = "inmueble";
$tabel    = "inmuebles";

// Create connection
$conn = mysqli_connect($hostname, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

//set array variable 
$results = array();

//talk to the db
$sql="SELECT count(*) as Total ,fecha  FROM inmuebles GROUP BY fecha
ORDER BY fecha DESC limit 100";
$result = mysqli_query($conn, $sql);

//count the rows and fields
$totalRows = mysqli_num_rows($result);
$totalFields = mysqli_num_fields($result);

//start the loop
for ( $i = 0; $i < $totalRows; ++$i ) {

//make it 2 dim in case you change your order
$results[$i] = mysqli_fetch_array($result); 
}

?>

html部分

<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi">  
</script>
<script type="text/javascript">
  google.load( 'visualization', '1', { 'packages': [ 'corechart' ] } );
  google.setOnLoadCallback( drawChart );

  function drawChart() {
    var data = new google.visualization.DataTable();

    data.addColumn( 'string', 'Fecha' );
    data.addColumn( 'number', 'Total' );

    data.addRows(100);
    <?php

    $i = 0;
   $numofloops = 100;

 while($i < $numofloops){

 echo "data.setValue($i, 0, '" . $results[$i]["fecha"] . "');";
 echo "data.setValue($i, 1,  " . $results[$i]["Total"] . ");";

 $i++; 
      }
    ?>

    var options = {title: 'Echangerate EUR - GBP',
                   vAxis: {title: "Total"},
                   hAxis: {title: "Fecha"},
      colors: ['red','#004411'] 
  };

    var chart = new 

 google.visualization.AreaChart(document.getElementById('chart_div'));
    chart.draw( data, options);
  }
</script>
</head>
<body>
 <div id="chart_div" style="width: 1500px; height: 800px;"></div>
</body>
</html>

提前非常感谢你this is how it looks like

0 个答案:

没有答案