1

我在从我的数据库中检索数据时遇到问题,下面是我在研究后尝试过的 PHP 代码,因为我是 PHP 新手,所以我在从我的数据库中检索数据时遇到了麻烦,该数据库在服务器上运行并拥有一个可视化折线图,使用 google chart developer。我希望有人可以帮助我解决这个问题。问题:代码正在与 DB 连接,但页面为空白,有时会显示未找到页面。我找不到调试此错误的方法,因此我将代码发布在 Stack Overflow 中。

<?php
// set the db connection  
$host ="localhost";
$user="xxxxxx";
$password="xxxxxx_0xxxxxA";
hash('xxxxxxxx',$password);
$port="xxxxxxxx";
$schema="xxxxx_vxxx4_xx2";

$conn = new mysqli($host, $user, $password, $schema , $port);
if ($conn->connect_error) {
die('Could not connect: ' .$conn->connect_error);
echo "Please contact you System administrator";
}
// done with connection

$query="select date,totalrain_mm from 'c_weather' where date between '2017-03-24' and DATE_ADD('2017-03-24',INTERVAL 60 DAY);"

$result = mysqli_query($conn, $query);

$rows = array();
$table = array();

$table['cols'] = array (
    array(
        'label' => 'Date Time',
        'type' =>  'datetime'
    ),
    array(
        'label' => 'Temperature',
        'type' =>  'number'
    )
   );


/**foreach($result as $row){
$temp = array();

//values
$temp[] = array ('v' => (date) $row['date']);
$temp[] = array ('v' => (float) $row['totalrain_mm']);
$rows[] = array('c' => $temp);
}

 $result->free();
 $table['rows'] = $rows;
 $jsonTable = json_encode($table, true);
 echo $jsonTable;**/
 while($row = mysqli_fetch_array($result)){
 $sub_array = array();
 $sub_array[] = array(
                    "v" => $row["datetime"]
);
$sub_array[] = array(
                    "v" => $row["totalrain_mm"]
);
$rows[] = array(
            "c" => $sub_array
 );
 }
 $table ['rows'] = $rows;
 $jsonTable = json_encode($table, true);
 echo $jsonTable;
 ?>


<html>
 <head>
 <script type="text/javascript" src="https://www.gstatic.com/charts   /loader.js"></script>
 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
google.charts.load('current',{'packages':['corechart']});
google.charts.setOnLoadCallback(drawchart);
function drawchart()
{
var data = new google.visualization.DataTable(
        <?php echo $jsonTable; ?>);


  chart.draw(data, google.charts.Line.convertOptions(options));

}
</script>
<style>
 .page-wrapper{ width:1000px; margin:0 auto;}
  </style>
 </head>
 <body>
<div class="page-wrapper">
<br />
    <div id="line_top_x" style="width: 100%; height:500px"></div>
</div>
</body>
</html>
4

0 回答 0