Here's something I need help on :
PHP Code:
# Categories and subcategories column
$parentcatquery = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "articles_category WHERE parentcategory=0 ORDER BY categoryorder");
if ($DB_site->num_rows($parentcatquery)>0)
{
while($parentcatrow=$DB_site->fetch_array($parentcatquery))
{
$parentid = $parentcatrow["articles_categoryid"];
$catname = $parentcatrow["categoryname"];
$parentcat = $parentcatrow["parentcategory"];
eval('$catlistbit .= "' . fetch_template('vbArticles_categorybit') . '";');
eval('$catlistbit .= "' . fetch_template('vbArticles_categorybit_pre') . '";');
$subcatquery = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "articles_category WHERE parentcategory = $parentid ORDER BY categoryorder");
if ($DB_site->num_rows($subcatquery)>0)
{
while($subcatrow=$DB_site->fetch_array($subcatquery))
{
$subcatid=$subcatrow["articles_categoryid"];
$subcatname=$subcatrow["categoryname"];
eval('$catlistbit .= "' . fetch_template('vbArticles_childcatbit') . '";');
}
}
eval('$catlistbit .= "' . fetch_template('vbArticles_categorybit_post') . '";');
}
}
I am trying to get the categories and then the subcategories of the parent category to display.
Is there anyway I can change things around to optimize what I am trying to do ?
My logic for the code above is:
I get the parent categories first ( those with parentcategory=0 meaning they are the parent categories already ), and for each of those parentcategories, query again for those categories whose parentcategory = the id of those parent categories.
Obviously this isn't as efficient as it can be.
As it is, this is probably the code portion contributing to the massive amount of queries on the page.
Any help would be most appreciated.