I am trying to create a web directory for a uni project. I have got two tables one is a list of all my categories and the second table has all the subcategories but i am struggling on how to display this with my queries. The following are my tables;
cat_id | category cat_id | sub_cat
1 | Bakeries 1 | Highfields Halal Bakery
2 | Business Stationery 1 | Delicious Corner
3 | Cafes
4 | Catering
5 | Finance
6 | Health
7 | Home
8 | Indian Sweets
9 | Motors
10 | Restaurants
11 | Shopping
12 | Takeaway
13 | Weddings
14 | Extra
15| Extra 2
At the moment I am running the query
$query = "SELECT *
FROM category
";
$result = mysql_query($query) or die('Error, query failed');
// print the student info in table
echo '<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>';
$i = 1;
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
// Display each record.
echo "<td><table border=\"1\" height=\"42\" width=\"212\" class=\"style1\">
<td class=\"col\"><width=\"103\" align=\"left\"><div style=\"padding-left:34px; padding-bottom:8px\">{$row['category']}</class>
</div></td>
</table></td>\n";
if (($i++ % 3) == false) {
echo "</tr>\n";
}
}
echo '</table>';
mysql_close(); // Close the database connection.
?>
where my data is displayed in a table e.g. (3 columns and 5 rows)
Bakeries Business Stationery Cafes (Shisha)
where i am struggling is that i would like to have the subcategories from table 2 to appear along each matching column. e.g.
Bakeries
Highfields Halal Bakery, Delicious Corner, etc..
If any1 can please help or guide me in the right direction.