最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - mysql data into Dojo datagrid table - Stack Overflow

programmeradmin1浏览0评论

Greetings all.

I have a php script calling MYSQL and displaying data in a table. It is rather ugly and I would rather have it displayed in a Dojo style table/datagrid. Can anyone point me in the right direction?

thanks!

Greetings all.

I have a php script calling MYSQL and displaying data in a table. It is rather ugly and I would rather have it displayed in a Dojo style table/datagrid. Can anyone point me in the right direction?

thanks!

Share Improve this question asked May 22, 2009 at 15:48 JoshJosh
Add a ment  | 

3 Answers 3

Reset to default 7

Passing data from MySQL to Dojo DataGrid requires a simple server side ponent. A recent discussion at Dojo forums demonstrates how to format MySQL query results in PHP into a format that Dojo's standard data stores understand:

// do your mysql query and get a result set
$arr = array();
while($row = mysql_fetch_object($result)){               
  $arr[] = $row;
}

// assuming you're running php version 5.2.x or higher
// this also assumes each row in the array has a identifer field 'id' and a field "name" in the database table which are returned from the mysql query.
$jsonStr = json_encode($arr);
echo "{'identifier':'id','label':'name','items':$jsonStr}";

Check out also this ment about PHP backend for sorting and searching. And this message for yet another PHP backend sample (no grid, though): Bringing PHP, MySQL, and Dojo together.

In addition, Dojo's tests are always a helpful resource. Like this one that demonstrates dispalying and editing data in a mysql database. But note: it's going to work only on your local box and only after you have edited username/password and pointed it to an existing database in sample protocol implementation. Plus, it's for the older Grid-ponent and hasn't been yet ported for the newer DataGrid. However, that file is an excellent starting point as it shows what functions are needed for editing data and how to get started with them.

I don't know Dojo's DataGrid, but here's some simple code I use with ExtJS:

while($row = db_fetch_array($db_result)) $rows[] = $row;
echo json_encode($rows);

http://jslib-test.amplio-vita/JSLib/demos/DBGrid/

发布评论

评论列表(0)

  1. 暂无评论