我想从MySQL数据库加载数据并将其显示在dhtmlxgrid上。 下面是从HTML文件中的代码:DHTMLX网格加载方法不从php文件加载数据
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my test</title>
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css"/>
<script src="codebase/dhtmlx.js"></script>
</head>
<body>
<div id="gridbox" style="width:100%;height:100%;"></div>
<script>
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("codebase/imgs"); //the path to images required by grid
mygrid.setHeader("uid,username,password, usertype,locname");//the headers of columns
mygrid.setInitWidths("100,250,150,100,*"); //the widths of columns
mygrid.setColAlign("right,left,left,left,left"); //the alignment of columns
mygrid.setColTypes("ro,ed,ed,ed,ed"); //the types of columns
mygrid.setColSorting("int,str,str,int,str"); //the sorting types
mygrid.init(); //finishes initialization and renders the grid on the page
mygrid.load("connector.php");
</script>
</body>
这里是connector.php文件:
<?php
require_once("samples/dhtmlxForm/06_data/php/connector/grid_connector.php");//includes related connector file
$res=mysql_connect("localhost","root","anahon1");//connects to server containing the desired DB
mysql_select_db("ssl_pmts"); //connects to the DB. 'sampledb' is the name of our DB
$conn = new GridConnector($res,"MySQL"); //connector initialization
$conn->dynamic_loading(100);
$conn->render_table("users","uid","uid,username,password,usertype,locname");
?>
而且有导致index.html文件是:
如果我直接打开connector.php文件,我得到以下内容:
问题是由于某种原因数据未在网格中列出。这个例子应该是直接的,但它不工作,我是dhtmlxgrid的新手,所以我不知道它是否是一个设置或我错过的代码。
和表结构是这样的:
CREATE TABLE `users` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL,
`usertype` int(11) NOT NULL,
`locname` varchar(45) DEFAULT NULL,
PRIMARY KEY (`uid`),
UNIQUE KEY `ID_UNIQUE` (`uid`),
UNIQUE KEY `name_UNIQUE` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
我们要求代码示例和输出HTML以文本形式提供,而不是图像 - 这通常是网络上各处的好建议。在这里,您可以选择您的代码并按下“代码”按钮进行适当的格式化。你会放弃它吗? – halfer 2014-12-03 17:23:29
对不起。现在代码是文本。 – 2014-12-03 17:49:54