我有一個由4列(id-symbol-name-contractnumber)組成的數據庫。所有4列及其數據都使用JSON顯示在用戶界面上。使用JSON檢索數據庫列
有一個函數可以將新列添加到數據庫,例如(countrycode)。
coulmn已成功添加到數據庫,但未能在用戶界面中顯示新增的coulmn。
下面是我的顯示列的代碼。
你能幫我嗎?
table.php
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="../../scripts/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
<script type="text/javascript" src="../../scripts/gettheme.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// prepare the data
var theme = getDemoTheme();
var source =
{
datatype: "json",
datafields: [
{ name: 'id' },
{ name: 'symbol' },
{ name: 'name' },
{ name: 'contractnumber' }
],
url: 'data.php',
filter: function()
{
// update the grid and send a request to the server.
$("#jqxgrid").jqxGrid('updatebounddata', 'filter');
},
cache: false
};
var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$("#jqxgrid").jqxGrid(
{
source: dataAdapter,
width: 670,
theme: theme,
showfilterrow: true,
filterable: true,
columns: [
{ text: 'id', datafield: 'id', width: 200 },
{ text: 'symbol', datafield: 'symbol', width: 200 },
{ text: 'name', datafield: 'name', width: 100 },
{ text: 'contractnumber', filtertype: 'list', datafield: 'contractnumber' }
]
});
});
</script>
</head>
<body class='default'>
<div id="jqxgrid"></div>
</div>
</body>
</html>
data.php
<?php
#Include the db.php file
include('db.php');
#Connect to the database
//connection String
$connect = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die('Could not connect: ' . mysql_error());
//Select The database
$bool = mysql_select_db($mysql_database, $connect);
if ($bool === False){
print "can't find $database";
}
$query = "SELECT * FROM pricelist";
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
$orders = array();
// get data and store in a json array
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$orders[] = array(
'id' => $row['id'],
'symbol' => $row['symbol'],
'name' => $row['name'],
'contractnumber' => $row['contractnumber']
);
}
echo json_encode($orders);
?>
你能指導我怎麼做 – arokia