title: how to fetch all the row of the result in php mysql?
body: <p>In my table I have 2 records with <code>companyid = 1</code> , but when I run the php below for <code>companyid = 1</code> it returns only the first one !<br>
  How can I fetch all the records?</p>
  
  <p>The php file:</p>
  
  <pre><code>if (isset($_GET["companyid"])) {
  $companyid = $_GET['companyid'];
  
  // get a product from products table
  $result = mysql_query("SELECT * FROM `products`         
                          WHERE companyid = $companyid;");
  
  if (!empty($result)) {      
  
      if (mysql_num_rows($result) &gt; 0) {
  
     while($row = mysql_fetch_assoc($result)){
        $product = array();
        $product["pid"] = $row["pid"];
        $product["productname"] = $row["productname"];        
      }
  
     $response["product"] = array();
  
         array_push($response["product"], $product);
  
          // success
         $response["success"] = 1;
  
     echo json_encode($response);
  
      } else {
          // no product found
          $response["success"] = 0;
          $response["message"] = "No product found";
  
          // echo no product JSON
          echo json_encode($response);
      }
  } else {
      // no product found
      $response["success"] = 0;
      $response["message"] = "No product found";
  
      // echo no users JSON
      echo json_encode($response);
  }
  } else {
  $response["success"] = 0;
  $response["message"] = "Required field(s) is missing";
  
  // echoing JSON response
  echo json_encode($response);
  }
  </code></pre>
  
  <p>Using <code>mysql_fetch_array</code> is happening the same. 
  it returns <code>{"product":[{"pid":"12371","productname":"test"}],"success":1}</code> 
  when i run a query without parameters <code>select * from table</code> using <code>mysql_fetch_array</code> it returns all the rows ..    </p>