title: MySQL Count in PHP while loop only returns one result then Null
body: <p>Ok, so I have some MySQL tables as follows:</p>
  
  <pre><code>Buildings
  Building-ID    Building-Name
  ===========----=============
  1              Building-1
  2              Building-2
  3              Building-3
  4              Building-4
  
  
  Building-1
  Mroom    State
  =====----======
  1        Booked
  2        Empty
  3        Empty
  4        Empty
  
  Building-2
  Mroom    State
  =====----======
  1        Booked
  2        Empty
  3        Empty
  4        Empty
  </code></pre>
  
  <p>And a query in PHP as follows (Ignore the hard coded while, I've simplified the code a bit):</p>
  
  <pre><code>$sql = "select * from Buildings";
  $result = mysql_query ($sql) or die(mysql_error());
  while ($row = mysql_fetch_array($result)) 
  { 
  $building[] = $row['ward_name'];
  }    
  
  
  $v1 = 0;
  while ($v1 &lt; 4)
  {
  $sql = "SELECT COUNT(*) FROM `$building[$v1]` WHERE state = 'Empty'";
  $result = mysql_query($sql) or die(mysql_error());
  $count = mysql_result($result, 00);
  
  var_dump($count[$v1]);
  $v1 = $v1 + 1;
  }
  </code></pre>
  
  <p>To my way of thinking this should create an array of the buildings contained in the "Buildings" table, start a loop, load the building name from the array and provide a row count for the table of how many rows contain "Empty" in the state column. What it actually does is provide a count for the first table and then provides "NULL" for the rest. </p>
  
  <p>I'd appreciate any help you can give me.</p>
  
  <p>Cheers!</p>