displaying one to many results in a single row

I am trying to print a table where the first set of columns are a single row.
The last column will display 2 results separated by a

Example
chapter, address, city, st, officer1
officer2
officer3

I have 2 tables one that contains the officers and one the chapter names and addresses - linked together by chapter number $num

I have tried several foreach’s and do while’s without any luck.

[php]
print “

”;
print “”;

$sql = mysql_query("select a.num, a.name as chapter, a.address, a.city, a.county, a.meeting, a.website, b.name, b.office from tbl_lodges as a, tbl_officers as b where a.num=b.num and a.body=“RAM” and b.body=“RAM” order by $order ");
while ($row = mysql_fetch_assoc($sql)) {
extract($row);

print “

”;
}
print “
Chapter Name City Stated Officers
$num $chapter $city $meeting $name
”;

[/php]

The results I get are:

chapter1, address, city, state, officer1
chapter1, address, city, state, officer2
chapter1, address, city, state, officer3
chapter2, address, city, state, officer1
chapter2, address, city, state, officer2
etc…

what i want is:
Chapter1, address, city, state, officer1
officer2
officer3
Chapter2, address, city, state, officer1
officer2
officer3
etc…

Any help would be much appreciated…

u nee 2 mysql querys and 2 loops.

[php]
print “

”;
print “”;

$sql = mysql_query(“select num, name as chapter, address, city, county, meeting, website from tbl_lodges where body=“RAM” order by $order “);
while ($row = mysql_fetch_assoc($sql))
{
extract($row);
print “

”;
}
print “
Chapter Name City Stated Officers
$num $chapter $city $meeting ”;
$sql2 = mysql_query(“select office, name from tbl_officers where num=$num and body=“RAM””);
while ($row2 = mysql_fetch_assoc($sql2)) print $row2[‘name’].”
”;
print “
”;

[/php]
i don’t know ur db-structur, but this should help u getting on the right track.

Thank You, I thought I had tried that, but evidently I did not have the 2nd query inside the first. Works like a champ when you have it correct…

Sponsor our Newsletter | Privacy Policy | Terms of Service