try using these two ways of code
1) This code will take categories from the category table
<?php
//get categories
$query = "SELECT * FROM category ORDER BY id DESC";
$result = mysql_query($query) or die("ERROR: Query failed [".$query."]<br>".mysql_error());
$xcate = 1;
echo("<table width='100%' border='1' bgcolor='#C56201'");
echo('<tr>');
for($xcate=1; $xcate<=mysql_num_rows($result); $xcate++){
$row = mysql_fetch_array($result);
$iSelected_Category = $row['category'];
echo('<td bgcolor="#C56201" align="center"><b><a href="index.php?category=' . $iSelected_Category . '"\n>'.$iSelected_Category. '</a></b> <font color="#FFBF13">(</font> <font color="#FFFFFF"><b>'.
$query = mysql_query("SELECT Count(*) as subcategory_count FROM subcategory where category = '$iSelected_Category'" ) .$row1=mysql_fetch_row($query).$totalsubcategories = $row1['subcategory_count'].'</b></font> <font color="#FFBF13"> )</font><br><font color="'.$color.'"><font size="-5">' . $row['description'] . '</font></font></td>'); //$row['category']
if($xcate%$category_col==0){
echo("</tr>"."\n");
}
}
echo '</table>';
?>
and....
2) this code will list categories from the sub-category table.....
<?PHP
//get categories
$query = "SELECT category,Count(*) as subcategory_count FROM subcategory GROUP by category";
$result = mysql_query($query) or die("ERROR: Query failed [".$query."]<br>".mysql_error());
$xcate = 1;
echo("<table width='100%' border='1' bgcolor='#C56201'");
echo('<tr>');
for($xcate=1; $xcate<=mysql_num_rows($result); $xcate++){
$row = mysql_fetch_array($result);
$iSelected_Category = $row['category'];
echo('<td bgcolor="#C56201" align="center"><b><a href="index.php?category=' . $iSelected_Category . '"\n>'.$iSelected_Category. '</a></b> <font color="#FFBF13">(</font> <font color="#FFFFFF"><b>'.
$row['subcategory_count'].
'</b></font> <font color="#FFBF13"> )</font><br><font color="' . $color . '"><font size="-5">' . $row['description'] . '</font></font></td>'); //$row['category']
if($xcate%$category_col==0){
echo("</tr>"."\n");
}
}
echo '</table>';
?>