kuau
04-02-2010, 04:24 AM
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. :)
$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'];
}
}
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. :)
$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'];
}
}