I’m a newbie so bear with me. I’m making a little forum for fun. Check it:
Categories:
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`position` int(11) NOT NULL,
PRIMARY KEY (`id`)
Forums:
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`description` text NOT NULL,
`position` int(11) NOT NULL,
`cat_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
I wonder how I should structure it so it loops out the categories and the assigned forums below it :/
Am I on the right path?
<?php
$query = mysql_query("SELECT * FROM forums JOIN...");
while ($row = mysql_fetch_array($query)) {..
?>
Maybe some sql guru can help me out.
Cheers!
If you want to display the Categories with Forums under them in your page, I suspect you’ll need to get a resultset for the categories first, and then iterate over this list with another loop for your forum list.
A join will give you a single recordset with the category in one column, and the forum in another, giving you many rows for a single category. As another answer has said, you’re not really looking for a join 🙂
Try something like this: