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!
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);
Passing data from MySQL to Dojo DataGrid requires a simple server side component. 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 comment 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-component 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.