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 JoshJosh3 Answers
Reset to default 7Passing 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/