我想從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