Having A Problem in getting results to display correctly I seem to be getting two sets of results displayed for categories "cat_title" when I only need it displayed once.
What is the best way around this does anyone know whether I should define using an mysql query or PHP.
function get_categories($id='') {
if($id != ""):
$id = mysql_real_escape_string($id);
$sql = "SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id
FROM subcategories AS s LEFT JOIN categories AS c ON c.cat_id = s.cat_id ORDER BY subcat_id ";
else:
$sql = "SELECT c.cat_id, c.cat_title, s.subcat_id, s.subcat_title, s.cat_id
FROM subcategories AS s LEFT JOIN categories AS c ON c.cat_id = s.cat_id ORDER BY subcat_id ";
endif;
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) != 0):
while($row = mysql_fetch_assoc($res)) {
$base_url = 'http://www.awholesaledirectory.com/';
$cat_title = $row['cat_title'];
$cat_title =preg_replace('/[^A-Za-z0-9-]+/', '-', $row['cat_title'] );
$category_title = strtolower( trim( $cat_title ) );
$subcat_title = $row['subcat_title'];
$subcat_title =preg_replace('/[^A-Za-z0-9-]+/', '-', $row['subcat_title'] );
$subcategory_title = strtolower( trim( $subcat_title ) );
echo '<ul><li><h2><a href="'.$base_url.'' .$category_title. '" title="' .$row['cat_title']. '">' .$row['cat_title']. '</a><h2></li>';
echo '<li><a href="'.$base_url.'' .$subcategory_title. '" title="' .$row['subcat_title']. '">' .$row['subcat_title']. '</a></li>';
}
else:
echo '';
endif;
}