【发布时间】:2014-06-15 00:14:54
【问题描述】:
我正在尝试在 php 中实现 ParamQuery 一个类似 excel 的插件。我正在尝试从生成 json 输出的 php 中获取数据。它正在正确获取,但我想在指定的 div:grid_array 中显示数据格式。我无法做到这一点所有字段都变为空白。
我的json输出代码:data.php
<?php
$conn = mysql_connect('localhost','root','pass');
if(!$conn){
die('Mysql connection error '.mysql_error());
}
$db = mysql_select_db('pop',$conn);
if(!$db){
die('Database selection failed '.mysql_error());
}
$sql = 'SELECT *FROM items';
$result = mysql_query($sql,$conn);
$data = array();
while($row = mysql_fetch_array($result)){
$row_data = array(
'id' => $row['Item_id'],
'Product' => $row['Product'],
'Brand' => $row['Brand'],
'Model' => $row['Model']
);
array_push($data, $row_data);
}
echo json_encode($data);
?>
我的 html 文件应该显示数据:
<html>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<!--PQ Grid files-->
<link rel="stylesheet" href="pqgrid.min.css" />
<script src="pqgrid.min.js"></script>
<!--PQ Grid Office theme-->
<link rel="stylesheet" href="themes/office/pqgrid.css" />
<script>
$(document).ready(function(){
var url = 'data.php';
$.getJSON(url, function(data) {
$.each(data, function(index, data) {
var obj = { width: 700, height: 400, title: "ParamQuery Grid Example",resizable:true,draggable:true };
obj.colModel = [{ title: "Id", width: 100, dataType: "integer" },
{ title: "Product", width: 200, dataType: "string" },
{ title: "Brand", width: 150, dataType: "string" },
{ title: "Model", width: 150, dataType: "string"}];
obj.dataModel = { data:data};
$("#grid_array").pqGrid(obj);
});
});
});
</script>
</head>
<body>
<div id="grid_array" style="margin:100px;">
</div>
</body>
</html>
【问题讨论】: