title: PHP Mysql Correctly Iterate Over Tables With Alias Names
body: <p>I have the following Mysql query:</p>
  
  <pre><code>$sql = "select r.brand AS brand, r.name AS name, r.cost AS cost, e.price AS price, d.shipping as shipping 
  FROM tab.rawproduct r 
  INNER JOIN price e ON r.housecode=e.housecode 
  INNER JOIN product d ON e.productid=d.productid  
  WHERE r.housecode='$housecode'";
  </code></pre>
  
  <p>The houscode is assigned to a variable which is then passed to the sql statement:</p>
  
  <pre><code>&lt;label&gt;Housecode:&lt;/label&gt;&lt;input class="boxes" type="text" name="housecode" value="&lt;?php echo $housecode; ?&gt;"&gt;&lt;br /&gt;        
  
  $housecode = $_POST['housecode'];
  </code></pre>
  
  <p>Housecode is submitted through a form with action set to $_SERVER[PHP_SELF]</p>
  
  <p>I am trying to iterate over the results with PHP with the following:</p>
  
  <pre><code>$result = $con-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt;0) {
  while($row = mysqli_fetch_array($result))  { 
      $brand = $row['brand'];     
      $housecode  = $row['housecode'];
      $name = $row['name'];
      $cost = $row['cost'];
      $salesprice = $row['price'];
      $shipraw = $row['shipping'];
      }
  } else {
  echo "0 Results";
  }
  
  $con-&gt;close();
  </code></pre>
  
  <p>Nothing is getting returned when a user submits a housecode and the "0 Results" is echoed.</p>
  
  <p>I have looked into this problem and read <a href="https://stackoverflow.com/questions/6934982/how-to-output-the-results-of-a-mysql-query-that-used-aliases">Lucas Knuth's post</a>:</p>
  
  <blockquote>
    <p>If two or more columns of the result have the same field names, the
    last column will take precedence. To access the other column(s) of the
    same name, you must use the numeric index of the column or make an
    alias for the column. For aliased columns, you cannot access the
    contents with the original column name. So, you can either use an AS
    in your SQL-query to set other names for the doubled rows or use the
    numbered indexes to access them.</p>
  </blockquote>
  
  <p>So I have used the AS keyword in the above query but I still don't get any results.  I have also tried changing to mysqli_fetch_row($result) and tried to assign the $row[0], <a href="https://stackoverflow.com/questions/6934982/how-to-output-the-results-of-a-mysql-query-that-used-aliases">1</a> ... etc instead.  Again no luck.</p>
  
  <p>When I run Apache error_log I get the following:</p>
  
  <p>Trying to get property of non-object on line 34.  On line 34 and 35 I have: </p>
  
  <pre><code>if ($result-&gt;num_rows &gt;0) {
  while($row = mysqli_fetch_array($result))  { 
  </code></pre>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Cheers</p>