Mysql data to Dojo datagrid

Welcome all.

I have a php script that calls MYSQL and displays data in a table. This is pretty ugly and I would prefer it to appear in the Dojo / datagrid stylesheet. Can anyone point me in the right direction?

thanks!

+1


a source to share


3 answers


Transferring data from MySQL to Dojo DataGrid requires a simple server side component. A recent discussion on the Dojo forums demonstrates how to format the results of MySQL queries in PHP into a format that the standard Dojo repositories 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 also this comment about PHP backend for sorting and searching . And this post is for yet another PHP backend example (no grid): Bringing PHP, MySQL and Dojo together .

Plus, Dojo tests is always a useful resource. Likewise, which demonstrates dispatching and editing data in mysql database . But note : it will only work locally , and only after you have edited your username / password and point it to an existing database in an example implementation of the protocol . Also, this is for the older Grid component and has not yet been ported for the new DataGrid. However, this file is a great starting point as it shows you what functions are needed to edit the data and how to get started with them.

+7


a source


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



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

      

+1


a source


0


a source







All Articles