如何访问另一个数据库,并在PHP中的2个不同图表上显示它?

时间:2018-10-01 06:48:25

标签: php mysqli charts

我想打开并从mysql访问我的2个不同的数据库,并将其分别显示在2个不同的图表上。我放置了一个引导轮播,可以简化2个图表之间的导航。下面是我的代码。

$connect = mysqli_connect("localhost", "root", "", "ws_monitoring");
$query = "SELECT mb_weight, mb_weight_dt, mb_refno, mb_date, mb_weight FROM conveyor_in_entry";
$result = mysqli_query($connect, $query);
$chart_data = '';
while($row = mysqli_fetch_array($result))
{
 $chart_data .= "{ mb_weight_dt:'".$row["mb_weight_dt"]."', mb_refno:".$row["mb_refno"].", mb_date:".$row["mb_date"].", mb_weight:".$row["mb_weight"]."}, ";
}
$chart_data = substr($chart_data, 0, -2);

$newconnection = mysqli_connect("localhost", "root", "", "cut" )
?>
 
 
<!DOCTYPE html>
<html lang="en">
 <head>
  <title>chart with PHP & Mysql | lisenme.com </title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 </head>
 <body>
  <br /><br />
  <div class="container">
  <h2>Carousel Test</h2>  
  <div id="carousel" class="carousel slide" data-ride="carousel" data-interval="2000">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel" data-slide-to="0" class="active"></li>
    <li data-target="#carousel" data-slide-to="1"></li>
    <li data-target="#carousel" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <div id="chart" class="chart" style="width:100%; height:300px;"></div>
    </div>
    <div class="item">
      <div id="chart1" class="chart" style="width:100%; height:300px;"></div>
    </div>
    <div class="item">
      <div id="chart2" class="chart" style="width:100%; height:300  px;"></div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel" href="#carousel" role="button" data-slide="prev">
    <span class="sr-only"></span>
  </a>
  <a class="right carousel" href="#carousel" role="button" data-slide="next">
    <span class="sr-only  "></span>
  </a>
</div>

 </body>
</html>
 
<script>
Morris.Line({
 element : 'chart',
 data:[<?php echo $chart_data; ?>],
 xkey:'mb_weight_dt',
 ykeys:['mb_refno', 'mb_date', 'mb_weight'],
 labels:['mb_refno', 'mb_date', 'mb_weight'],
 hideHover:'auto',
 stacked:true
});
</script>

Chart2将来自具有不同属性的不同数据库中的新数据库,到目前为止,当我为mysql创建另一个查询时,第二个图表中出现的数据库与第一个数据库相同。

0 个答案:

没有答案