Displaying category heading
Posted: Sun Apr 02, 2006 9:59 am
I have the following function that retrieves a category heading and all the sub-categories associated with the main one. This is working properly apart form not displaying the main category heading.
The function that retrieves the data is
To display it on the page I am using the following, starting by calling the function
All of this is working perfectly apart form displaying the main category heading. I assume it is because this is outside of the loop as I only need this to be displayed once, where the sub-categories need to be looped. What I need is for the main category heading to be displayed once followed by however many sub-categories there are.
The function that retrieves the data is
Code: Select all
/***************************************************************************/
// Function : list_scats()
// Description : Gets a list of sub-categories to show
function list_scats($id) {
global $db;
$sql = "SELECT COUNT(skinz_images.subcat_id) AS total
, skinz_subcats.subcat_id
, skinz_subcats.subcat_name
, skinz_cats.cat_name
FROM
skinz_subcats
LEFT JOIN
skinz_cats
ON
skinz_cats.cat_id = skinz_subcats.cat_id
LEFT JOIN
skinz_images
ON
skinz_images.subcat_id = skinz_subcats.subcat_id
WHERE
skinz_subcats.cat_id = '".$id."'
AND
skinz_subcats.status = '1'
AND
skinz_images.subs_status = '1'
GROUP BY
skinz_subcats.subcat_id
, skinz_subcats.subcat_name";
$result = $db->sql_query($sql);
return $result;
}Code: Select all
$list_scats = list_scats($id);
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="tablebg">
<tr>
<th><?php echo list_scats($id) ?></th>
</tr>
<tr class="row1">
<td>
<?php while($row = $db->sql_fetchrow($list_scats)) {
echo '<a href=preview.'.$phpEx.'?id='.$row['subcat_id'].'>'.$row['subcat_name'].'</a> ('.$row['total'].')<br />';
} ?>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>