Guest User

Untitled

a guest
Dec 5th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. $user = "u348833238_rest"; /* User */
  4. $password = "a!23286029"; /* Password */
  5. $dbname = "u348833238_rest"; /* Database name */
  6. $host = "localhost";
  7.  
  8. $con = mysqli_connect($host, $user, $password, $dbname);
  9. // Check connection
  10. if (!$con) {
  11. die("Connection failed: " . mysqli_connect_error());
  12. }
  13.  
  14. // $sel = mysqli_query($con,"select * from restaurant");
  15.  
  16. // $data = array();
  17.  
  18. // while ($row = mysqli_fetch_array($sel)) {
  19. // $data[] = array("dishes" => ["name"=>$row['food'], "price"=>$row['price']] , "category"=>$row['category']);
  20. // }
  21. // echo json_encode($data);
  22.  
  23.  
  24. $sel = mysqli_query($con,"select distinct category from restaurant");
  25.  
  26. $data = array();
  27.  
  28. while ($row = mysqli_fetch_array($sel)) {
  29.  
  30. $c = $row['category'];
  31.  
  32. $sel2 = mysqli_query($con,"select * from restaurant where category = $c ");
  33.  
  34. $data2 = array();
  35.  
  36. while ($row2 = mysqli_fetch_array($sel2)){
  37. $data2[] = array("name"=>$row2['food'], "price"=>$row2['price']);
  38. }
  39.  
  40. // echo $data2;
  41.  
  42. $data[] = array("category"=>$row['category'], "dishes"=>$data2);
  43. }
  44.  
  45. // echo $data;
  46. echo json_encode($data);
  47.  
  48. ?>
Add Comment
Please, Sign In to add comment