title: select from one table, count from another where id's linked
body: <p>heres my code:</p>
  
  <pre><code>$sql = mysql_query("select c.name, c.address, c.postcode, c.dob, c.mobile, c.email, 
                      count(select * from bookings where b.id_customer = c.id) as purchased, count(select * from bookings where b.the_date &gt; $now) as remaining, 
                      from customers as c, bookings as b 
                      where b.id_customer = c.id
                      order by c.name asc");
  </code></pre>
  
  <p>you can see what i am trying to do, but im not sure how to write this query properly.</p>
  
  <p>heres the error i get:</p>
  
  <blockquote>
    <p>Warning: mysql_fetch_assoc(): supplied
    argument is not a valid MySQL result
    resource</p>
  </blockquote>
  
  <p>heres my mysql_fetch_assoc:</p>
  
  <pre><code>&lt;?php
  
  while ($row = mysql_fetch_assoc($sql))
  {
      ?&gt;
  
      &lt;tr&gt;
      &lt;td&gt;&lt;?php echo $row['name']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['mobile']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['email']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['purchased']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['remaining']; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;?php   
  }
  
  ?&gt;
  </code></pre>