Guest User

Untitled

a guest
Jul 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <?php
  2.  
  3. $total = isset($_GET['total']) ? $_GET['total'] : 50;
  4. $recs = isset($_GET['recs']) ? $_GET['recs'] : $total;
  5. $offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
  6. $data = array();
  7. $fields = isset($_GET['fields']) ? split(",",$_GET['fields']) :
  8. array('foo','bar','baz');
  9.  
  10. if ($total > 100) {
  11. $total = 100;
  12. } elseif ($total < 0) {
  13. $total = 0;
  14. }
  15. if ($recs > 100) {
  16. $recs = 100;
  17. } elseif ($recs < 0) {
  18. $recs = 0;}
  19. if ($offset > 100) {
  20. $offset = 100;
  21. } elseif ($offset < 0) {
  22. $offset = 0;
  23. }
  24.  
  25. $recs += $offset;
  26.  
  27. for ($i = $offset; $i < $recs; ++$i) {
  28. $rec = array();
  29. for ($j = count($fields) - 1; $j >= 0; --$j) {
  30. $rec[$fields[$j]] = $j ? $fields[$j].($i) : $i;
  31. }
  32. $data[] = $rec;
  33. }
  34. header('Content-type: application/json');
  35. echo(json_encode(array("total" => $total,"offset" => $offset, "records" => $data
  36. )));
  37.  
  38. ?>
Add Comment
Please, Sign In to add comment