Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Access-Control-Allow-Origin: *");
- $user = "u348833238_rest"; /* User */
- $password = "a!23286029"; /* Password */
- $dbname = "u348833238_rest"; /* Database name */
- $host = "localhost";
- $con = mysqli_connect($host, $user, $password, $dbname);
- // Check connection
- if (!$con) {
- die("Connection failed: " . mysqli_connect_error());
- }
- // $sel = mysqli_query($con,"select * from restaurant");
- // $data = array();
- // while ($row = mysqli_fetch_array($sel)) {
- // $data[] = array("dishes" => ["name"=>$row['food'], "price"=>$row['price']] , "category"=>$row['category']);
- // }
- // echo json_encode($data);
- $sel = mysqli_query($con,"select distinct category from restaurant");
- $data = array();
- while ($row = mysqli_fetch_array($sel)) {
- $c = $row['category'];
- $sel2 = mysqli_query($con,"select * from restaurant where category = $c ");
- $data2 = array();
- while ($row2 = mysqli_fetch_array($sel2)){
- $data2[] = array("name"=>$row2['food'], "price"=>$row2['price']);
- }
- // echo $data2;
- $data[] = array("category"=>$row['category'], "dishes"=>$data2);
- }
- // echo $data;
- echo json_encode($data);
- ?>
Add Comment
Please, Sign In to add comment