I'm trying loop categories so I get main category then the sub cats listed below them for a download section mod I'm building.
Here's the code thus far:
PHP Code:
$cats = $vbulletin->db->query("SELECT * FROM `" . TABLE_PREFIX . "xsdl_cats` WHERE sub_cat = '0' AND par_cat = '0'");
while($category = $vbulletin->db->fetch_array($cats))
{
$cid = $category['cid'];
$cname = $category['cat_name'];
// $rating = round($entry['rating']);
$description = $category['description'];
$subcat = $category['sub_cat'];
$file_loc = $category['file_loc'];
$screen_loc = $category['screen_loc'];
$query = $db->query_first("
SELECT COUNT(`dlid`) AS `total`
FROM `" . TABLE_PREFIX . "xs_downloads`
WHERE cat_id = " . $category['cid'] . "
");
$subs = $vbulletin->db->query("SELECT * FROM `" . TABLE_PREFIX . "xsdl_cats` WHERE sub_cat = '1' AND par_cat = '$cid'");
while($sub_cats = $vbulletin->db->fetch_array($subs))
{
$scid = $sub_cats['cid'];
$scname = $sub_cats['cat_name'];
// $srating = round($sub_cats['rating']);
$sdescription = $sub_cats['description'];
$ssubcat = $sub_cats['sub_cat'];
$sfile_loc = $sub_cats['file_loc'];
$sscreen_loc = $sub_cats['screen_loc'];
}
$count = $query['total'];
$key[0] = $cid;
$key[1] = $cname;
$key[2] = $description;
foreach ($key as $value)
{
echo $value;
$sub[0] = $scid;
$sub[1] = $scname;
$sub[2] = $sdescription;
foreach ($sub as $value)
{
echo '<a href="downloads.php?do=cat&id=' . $value . '">' . $value . '</a><br />' . $value . '';
}
}
Any help much appreciated.
Steve