title: Php web service to get data in json format
body: <p>I have 2 database tables </p>
  
  <ol>
  <li><code>main_menu</code> which has 3 columns <code>id, item_name, img</code></li>
  <li><code>sub_menu</code> which has columns <code>id, sub_item_name, item_name, add_price, img</code></li>
  </ol>
  
  <p>Now I am trying to get all sub menu under master menu when user clicks on master menu</p>
  
  <p>eg. </p>
  
  <pre><code>select * from sub_menu where item_name="Cafe"
  </code></pre>
  
  <p>it should display all sub menu under <code>Cafe</code>.</p>
  
  <p>And here is the web service I wrote to do that and get data in json format</p>
  
  <pre><code>    &lt;?php
      $response = array();
  
      // include db connect class
      require_once __DIR__ . '/db_connect.php';
  
     // connecting to db
      $db = new DB_CONNECT();
  
      // check for post data
     if (isset($_GET["item_name"])) {
  
  
  // get a product from products table
  $result = mysql_query("SELECT * FROM sub_menu WHERE item_name ='".$_GET["item_name"]."'");
  echo $result;
  if (!empty($result)) {
      // check for empty result
  
      if (mysql_num_rows($result) &gt; 0) {
  
          $result = mysql_fetch_array($result);
          $sub_menu = array();
          $sub_menu["id"] = $result["id"];
          $sub_menu["item_name"] = $result["item_name"];
          $sub_menu["sub_item_name"] = $result["sub_item_name"];
          $sub_menu["add_price"] = $result["add_price"];
          $sub_menu["img"] = $result["img"];
          // success
          $response["success"] = 1;
  
          // user node
          $response["sub_menu"] = array();
  
          array_push($response["sub_menu"], $sub_menu);
  
          // echoing JSON response
          echo json_encode($response);
      } else {
          // no product found
          $response["success"] = 0;
          $response["message"] = "No sub menu found";
  
          // echo no users JSON
          echo json_encode($response);
      }
  } else {
      // no product found
      $response["success"] = 0;
      $response["message"] = "No menu found";
  
      // echo no users JSON
      echo json_encode($response);
  }
      } else {
  // required field is missing
  $response["success"] = 0;
  $response["message"] = "Required field(s) is missing";
  
  // echoing JSON response
  echo json_encode($response);
      }
      ?&gt;
  </code></pre>
  
  <p>Now the problem is I am only getting first data only, it should display all data </p>
  
  <p>Query is working fine in mysql, I checked that. The problem is somewhere in my php service.</p>