Hi All,

I have a PHP / SQL scripting platform that generates a list of all the created categories on a left-side navigation menu and I only want it to show the category IF there is something in it and not empty. Otherwise I have 40 categories listed and only 4 or 5 actually have anything in them.

I get the idea of the NOT NULL inside a SQL QUERY call inside the PHP page, but this category has no specific field in the table structure that shows if empty or contains listings (or data - not empty).

The problem I have is that the categories are being generated there and listed out by the call code:

// prepare categories on the left side ... 
$i 	= 0;
$sql_query 	= "SELECT * FROM setup_category WHERE category_parent = '0' ORDER BY category_name ASC";
$result  = mysql_query($sql_query) or die(mysql_error());
$found  = mysql_num_rows($result); 
while($row 	= mysql_fetch_array($result)) {

$left_category_id		= $row[category_id];
$left_category_parent	= $row[category_parent];
$left_category_name	= $row[category_name];
$left_category_name_rewrite	= convert_rewrite($left_category_name);
$left_category_last	= "no"; 
$left_category_url	= "site_browse.php?cat=$left_category_id";

$sql_query_listing    	= " 
SELECT * FROM listing 
listing_category 	LIKE  '%-$left_category_id-%'  AND
listing_date_expired	>=	'$date_database'	  AND
listing_status		 =	'approved' 
$result_listing       = mysql_query($sql_query_listing) or die(mysql_error());
$left_category_total 	= mysql_num_rows($result_listing); 

if ($i == $found -1) { $left_category_last	= "yes"; } 
if ($status_url_rewrite == "yes") { $left_category_url	= "browse-$left_category_id 1-0-$left_category_name_rewrite.php";	} 

$arr_left_catmain_id[$i]	 =  $left_category_id;
$arr_left_catmain_name[$i]	= $left_category_name;
$arr_left_catmain_last[$i]	= $left_category_last;
$arr_left_catmain_link[$i]	= $left_category_url;
$arr_left_catmain_total[$i]	= $left_category_total;
and then inside the page template that calls the category list is a call tag - and populates every category even if empty:

{$left_catmain_name[var]} ({$left_catmain_total[var]})

My question is that since there is no table area listed as left_catmain_total that is used to populate the categories in the navigation bar and looks to be listing them all just if they have a name CAN I PLACE SOME CODE to have it ONLY display categories that have that [var] part of the code :


as being full and not empty [0] ?

An example right now is dentists (0) as there are no listings yet added to that category and then the massage therapist (3) is not empty as there are 3 listings already in it...

Does anyone know a way using PHP or PHP / SQL combo to only display the categories IF they have 1, 2, 3, etc.. listings inside them and are not the (0) empty categories?

Thanks in advance,