Hello,
On one of my websites - http://www.staff.ie - you will see there is a section called "Jobs by Category".
I want to display the number of jobs per category next to each category name.
So instead of having -
IT / Programming
IT / Programming (50)
The problem is, when I try to implement this it dramatically slows down the loading of the page (from about 1 second to about 10 seconds.)
This is the code which displays the categories and number of jobs per categories -
// while $a2 is each category
while($a2 = $db->sql_fetchrow())
{
// get the count of active jobs in this specific category
$q2 = "select count(*) as cat_total from job_offers, job_offers_categories where job_offers.job_status = 'active' and job_offers.job_id = job_offers_categories.job_id and job_offers_categories.job_category_id = '$a2[category_id]' ";
$db1->sql_query($q2);
$a3 = $db1->sql_fetchrow();
$categories .= "<td width=\"33%\"><a href=\"category/$a2[category_id].html\" class=\"vm_link2\">$a2[category_name] ($a3[cat_total])</a></td>";
}
At the moment I have commented out these bits -
// get the count of active jobs in this specific category
$q2 = "select count(*) as cat_total from job_offers, job_offers_categories where job_offers.job_status = 'active' and job_offers.job_id = job_offers_categories.job_id and job_offers_categories.job_category_id = '$a2[category_id]' ";
$db1->sql_query($q2);
$a3 = $db1->sql_fetchrow();
Can any of you think of a better way to count the number of jobs per category without dramitically slowing down the page load time?
Any help greatly appreciated.
Thank you!