/ Published in: PHP
This snippet references the data access class I linked to.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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;
URL: http://snipplr.com/view/4715/simple-data-access-class/