title: Trick Question; Showing 'nr of results' of MySql search
body: <p>I have a classifieds website, and users can search ads.</p>
  
  <p>The results are displayed in three tabs on top of the page. These three are "<strong>All</strong>", "<strong>Private</strong>", and "<strong>Company</strong>".
  Each tab has a nr attached to it, which represents the nr of ads found in that tab.</p>
  
  <p>So for example:</p>
  
  <pre><code>  All     Private     Company
     5         3           2
  </code></pre>
  
  <p><code>All</code> is just a total of private+company!</p>
  
  <p>I am using MySql as a database.</p>
  
  <p>I am trying to figure out a way to find out these "numbers of ads found" for each tab.</p>
  
  <p>I have one way of doing this, which is like this, but gives me a headache because it is so messy:</p>
  
  <pre><code>$query = "SELECT SQL_CACHE * FROM classified WHERE classified.classified_id=$id";
  
          if ($adtypes=="Private"){
          $query_priv_comp = "SELECT SQL_CACHE * FROM classified WHERE priv_comp='Company'";
          }
          else {
          $query_priv_comp = "SELECT SQL_CACHE * FROM classified WHERE priv_comp='Private'";
          }
  
          switch ($adtypes){ 
              case "Private":
                  $query.= " AND classified.priv_comp='Private'";
              break;
  
              case "Company":
                  $query.= " AND classified.priv_comp='Company'";
              break;
          }
  
          $qry_result = mysql_query($query); // main query
          $result_priv_comp = mysql_query($query_priv_comp); // second query
  
          $num_priv_comp = mysql_num_rows($result_priv_comp);
          if ($adtypes=="All"){
          $num_total = mysql_num_rows($qry_result);
          }
          else if ($adtypes!="All"){
              $num_total=mysql_num_rows($qry_result) + mysql_num_rows($result_priv_comp);
          }
  
          if ($adtypes=="Private"){
          $num_private = $num_total - $num_priv_comp;
          $num_company = $num_priv_comp;
          }
          else {
          $num_company = $num_total - $num_priv_comp;
          $num_private = $num_priv_comp;
          }
  </code></pre>
  
  <p>Do you know of any other way which this can be done?</p>
  
  <p>Thanks</p>
  
  <p><strong>BTW</strong>: I need the rows too, in order to display information to the user of the ads found!</p>