Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $total = isset($_GET['total']) ? $_GET['total'] : 50;
- $recs = isset($_GET['recs']) ? $_GET['recs'] : $total;
- $offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
- $data = array();
- $fields = isset($_GET['fields']) ? split(",",$_GET['fields']) :
- array('foo','bar','baz');
- if ($total > 100) {
- $total = 100;
- } elseif ($total < 0) {
- $total = 0;
- }
- if ($recs > 100) {
- $recs = 100;
- } elseif ($recs < 0) {
- $recs = 0;}
- if ($offset > 100) {
- $offset = 100;
- } elseif ($offset < 0) {
- $offset = 0;
- }
- $recs += $offset;
- for ($i = $offset; $i < $recs; ++$i) {
- $rec = array();
- for ($j = count($fields) - 1; $j >= 0; --$j) {
- $rec[$fields[$j]] = $j ? $fields[$j].($i) : $i;
- }
- $data[] = $rec;
- }
- header('Content-type: application/json');
- echo(json_encode(array("total" => $total,"offset" => $offset, "records" => $data
- )));
- ?>
Add Comment
Please, Sign In to add comment