Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. include_once './DbConnect.php';
  3.  
  4. function getCategories(){
  5.  
  6. $db = new DbConnect();
  7.  
  8. $tmp = array();
  9.  
  10. // array for json response
  11. $response = array();
  12. $response["categories"] = array();
  13.  
  14. // Mysql select query
  15. $result = mysql_query("SELECT * FROM categories");
  16.  
  17. while($row = mysql_fetch_array($result)){
  18. // temporary array to create single category
  19. $tmp["id"] = $row["id"];
  20. $tmp["name"] = $row["name"];
  21.  
  22. // push category to final json array
  23. $response = array_push($response["categories"], $tmp);
  24. }
  25.  
  26. // keeping response header to json
  27. header('Content-Type: application/json');
  28.  
  29. // echoing json result
  30. echo json_encode($response);
  31. }
  32.  
  33. getCategories();
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement