標籤:style blog http color os ar 使用 sp 檔案
從資料庫載入資料
這篇我們介紹從MySQL資料庫中載入資料到表格
我們使用 MySql的資料庫dhtmlx_tutorial 和表contacts
樣本使用的是PHP平台和dhtmlxConnector 協助庫 因為這是實現伺服器端邏輯最簡單的方法 資料以XML格式輸出。
環境自己搭建 相信C#的朋友 從資料庫擷取資料轉化盛XML也不是難事。
載入資料到表格:
1.找到”db.sql“檔案將表匯入到本機資料庫
2.在codebase 檔案中添加一個php檔案codebase
3.下載dhtmlxConnector 庫 (下載連結)
4.在codebase檔案夾中添加connector檔案夾
5.在data檔案中添加contacts.php
6.在contacts.php中添加php代碼
<?phprequire("../codebase/connector/grid_connector.php");//adds the connector engine$res=mysql_connect("localhost","user","password");//connects to server with dbmysql_select_db("dhtmlx_tutorial");//connects to db with name "dhtmlx_tutorial" $conn = new GridConnector($res); //initializes the connector object$conn->render_table("contacts","contact_id","fname,lname,email"); //loads data//the method takes: the table‘s name, the id field, a list of fields to load
擷取從資料庫載入資料和建立XML的細節 參考 動態載入大資料
7.使用load() 方法載入資料到表格
contactsGrid.load("data/contacts.php");
dhtmlx.js已經包含了 dhtmlxConnector 方法 ,所以我們不必再額外引入其他檔案。
DHTMLX 前端架構 建立你的一個應用程式 教程(六)-- 表格載入資料