http://www.urbancanada.com/photos/
Part 1
What I want to do is display the subcategories below the parent category. I really don't have any idea how to do this.
My database setup is like this:
- photo (Contains the photo's)
- photo_cat (Contains the category)
photo_cat is setup like this:
CREATE TABLE photo_cat (
cat_id int(11) NOT NULL auto_increment,
category varchar(55) NOT NULL default '',
description text NOT NULL,
subcat varchar(55) NOT NULL default '',
parent_id varchar(55) NOT NULL default '',
PRIMARY KEY (cat_id)
) TYPE=MyISAM;
If the category is a cub category "subcat" is "yes" and if it is a subcategory then parent_id has the parent categories cat_id number.
In the following code I would like to display the categories subcategories, where it sais "#sub_cat(s)".
<?php
require('config.php');
$sql = "SELECT * FROM photo_cat where subcat='no' order by category asc";
if (!$result = mysql_query($sql)) {
print "Invalid query ($sql) : " . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result)) {
$cat_id = $row[cat_id];
$description = $row[description];
$category = $row[category];
$q = mysql_query("SELECT * FROM photo WHERE cat_id = '$cat_id'");
$count = mysql_num_rows($q);
print "<tr>
<td width=\"90%\" bgColor=\"#EEEEEE\"><B><a href=\"photocat.php?cat_id=$cat_id\"><font color=\"#000000\" style=\"font-size: 11px\" face=\"Verdana\">$category</a></B><br><font style=\"font-size: 10px\">#sub_cat(s)</td>
<td width=\"10%\" bgColor=\"#EEEEEE\"><center><font color=\"#000000\" style=\"font-size: 10px\" face=\"Verdana\">$count</a></B></td>
</tr>";
}
?>
Part 2
I need to be able to count the # of photos in each category (including subcategory) instead of just counting the number of photos in the parent category (there will be none).
Hope someone can help