/ Published in: PHP
URL: http://snipplr.com/view/4715/simple-data-access-class/
This snippet references the data access class I linked to.
Expand |
Embed | Plain Text
// query parameters $p[0] = 'id'; $p[1] = 'name'; // query database $result = $dal->selectFieldsOrder('inventory_categories', $p, 'name asc'); $numRows = $result->num_rows; $loopCount = 1; $json = '{ ' . '"categories" : ['; // build json string while ($row = $result->fetch_assoc()) { $json .= '{ ' . '"id" : "' . $row['id'] . '", ' . '}'; // add comma if if ($loopCount < $numRows) { $json .= ', '; $loopCount++; } } $json .= '] ' . '}'; echo $json;
Comments
Subscribe to comments
You need to login to post a comment.

or just use json_encode() (from php 5.2.0): http://php.net/manual/en/function.json-encode.php