I thought this would be fairly easy but I am having trouble.
I have a list of 200 member names. The members can belong to more than one category. There is a member table, a category table, and a membercat table that has 2 fields: member_id and cat_id.
I would like to list the members grouped by category with a subheading every time the category changes.
The SQL command I tried to join the 3 tables produced 66,220 results (!). So I am having trouble with that. Or do I do the SQL command on just 2 tables inside the while loop? I'd like to learn the best way to do it. I read the php manual but...
I figure there will be a foreach loop for the categories and a while loop inside to list the members (?). Is it something like this? Thanks for any help.
Code:$sql = "SELECT * FROM category"; $resultcat = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error()); foreach ($cat_id as $category){ while($member = mysql_fetch_assoc($result2)){ echo $member['company']; } }




Reply With Quote

Bookmarks