I have a classifieds website, and users can search ads.
The results are displayed in three tabs on top of the page. These three are "All", "Private", and "Company". Each tab has a nr attached to it, which represents the nr of ads found in that tab.
So for example:
All Private Company
5 3 2
All
is just a total of private+company!
I am using MySql as a database.
I am trying to figure out a way to find out these "numbers of ads found" for each tab.
I have one way of doing this, which is like this, but gives me a headache because it is so messy:
$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;
}
Do you know of any other way which this can be done?
Thanks
BTW: I need the rows too, in order to display information to the user of the ads found!