希望有人能找到我的问题的解决方案。我正在尝试使用谷歌地图和 PHP 创建仪表板。在尝试将其放入 MVC 模式之前,我能够显示图表,现在我得到的只是错误。(代码分为各自的文件夹模型、视图和控制器,根目录中有一个索引文件)。这是我到目前为止的代码
指数
<?php
include_once ("Design/includes.php");
$controller = new Controller();
$controller->invoke();
?>
控制器
<?php
class Controller {
public $model;
public function __construct()
{
$this->model = new tableModel();
}
public function invoke()
{
$this->model -> tableData();
include 'view/homeScreen.php';
}
}
?>
模型(这是表格,另一个模型在同一个文件夹中但完全相同)
<?php
class tableModel {
public function tableData(){
global $con;
$result = mysqli_query ( $con, "SELECT fk_EXECUTION_LAB_MACHINE as LAB_MACHINE, COUNT(fk_EXECUTION_LAB_MACHINE) as TOTAL
FROM EXECUTION_QUEUE
WHERE fk_EXECUTION_LAB_MACHINE IS NOT NULL and WEEK (TEST_START_TIME) = WEEK( current_date ) -1 AND YEAR( TEST_START_TIME) = YEAR( current_date )
GROUP BY fk_EXECUTION_LAB_MACHINE order by count(fk_EXECUTION_LAB_MACHINE) desc;");
$rows = array();
$table = array();
$table['cols'] = array(
// Labels for chart/column titles
array('label' => 'LAB_MACHINE', 'type' => 'string'),
array('label' => 'TOTAL', 'type' => 'number')
);
//Getting results array and populating table
$rows = array();
while($r = mysqli_fetch_array($result)) {
$temp = array();
$temp[] = array('v' => (string) $r['LAB_MACHINE']);
$temp[] = array('v' => (int) $r['TOTAL']);
$rows[] = array('c' => $temp);
}
//Get table in JSON format
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
return $jsonTable;
mysqli_close ( $con );
}
}
?>
这是视图
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript"
src="http://underscorejs.org/underscore-min.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
var Dash = {
widget : {},
render : {
pie : function() {
var view = new google.visualization.DataView(Dash.data.pieEg);
var options = {
animation : {duration : 300},
chartArea : {width : '100%', height : '70%'},
is3D: 'true',
title : 'Pie Chart',
tooltip : {showColorCode : true}
};
Dash.widget.pie.draw(view, options);
},
table : function() {
Dash.widget.table = new google.visualization.ChartWrapper({
chartType: 'Table',
dataTable: Dash.data.tableEg,
options: {
allowHtml : true
},
containerId: 'table_div'
});
Dash.widget.table.draw();
}
},
util : {
bootstrap : function(){
Dash.util.prepareData();
Dash.render.table();
Dash.util.createWidgets();
Dash.util.refreshCharts();
},
createWidgets : function(){
Dash.widget.pie = new google.visualization.PieChart(document.getElementById('pie_div'));
},
refreshCharts : function(tableEg){
if (!tableEg || tableEg.length === 0) {
tableEg = [1,2];
}
Dash.render.pie(tableEg.slice(0));
},
prepareData : function(){
Dash.data = {};
var tableData = $.ajax({
url: "tableModel.php",
dataType:"json",
async: false
}).responseText;
Dash.data.tableEg = new google.visualization.DataTable(tableData);
var chartData = $.ajax({
url: "pieModel.php",
dataType:"json",
async: false
}).responseText;
Dash.data.pieEg = new google.visualization.DataTable(chartData);
}
}
};
google.load('visualization', '1', {
'packages':['corechart'],
'callback': Dash.util.bootstrap
});
</script>
</head>
<body>
<div id="row1">
<div id="pie_div"
style="width: 410px; height: 410px; display: inline-block"></div>
</div>
<div id="row2" style="width: 900px">
<div id="table_div" style="width: 700px; display: inline-block"></div>
<div id="gauge" style="display: inline-block; float: right"></div>
</div>
</body>
</html>
正如我之前所说,当我将视图和表数据放在一个文件夹中时,这些图表运行良好,但现在我将其放入 MVC 样式中,它不再起作用。这是我得到的错误
{"cols":[{"label":"LAB_MACHINE","type":"string"},{"label":"TOTAL","type":"number"}],"rows":[{"c":[{"v":"LIT-QAVIST-20"},{"v":1}]},{"c":[{"v":"LIT-QAVIST-25"},{"v":1}]}]}
Warning: mysqli_query(): Couldn't fetch mysqli in C:\Users\n0237569\workspace\Dashboard MVC\Design\model\tableModel.php on line 11
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\Users\n0237569\workspace\Dashboard MVC\Design\model\tableModel.php on line 28
{"cols":[{"label":"LAB_MACHINE","type":"string"},{"label":"TOTAL","type":"number"}],"rows":[]}
Warning: include(view/homeScreen.php): failed to open stream: No such file or directory in C:\Users\n0237569\workspace\Dashboard MVC\Design\controller\Controller.php on line 17
Warning: include(): Failed opening 'view/homeScreen.php' for inclusion (include_path='.;C:\php\pear') in C:\Users\n0237569\workspace\Dashboard MVC\Design\controller\Controller.php on line 17
正如您从第一个错误中看到的那样,它以 json 格式返回数据,但我不确定接下来会发生什么。
这是包含文件夹的内容,因为最后两个错误引用了它
包括
<?php
require_once "Design/config.php";
require_once "Design/connection.php";
require_once "Design/model/pieModel.php";
require_once "Design/model/tableModel.php";
require_once "Design/controller/Controller.php";
?>
任何帮助将不胜感激
谢谢