Forum Moderators: coopster
// the query
$sql_test = mysql_query ("
SELECT * FROM `members`
ORDER BY `name` ASC
")
$test = mysql_fetch_assoc ($sql_test);
mysql_close();
// if want to test the result
do{
echo $test['name'].' - '.$test['address'].'
';
}while ($test = mysql_fetch_assoc ($sql_test));
?>
I'd love to list the services from the services table within the loop. Is this even possible?
I'm use to asp.
I would normally just use 2 select statements.
Set rs = ("Select * From members ORDER BY NAME;")
returncount = 0
Do While Not rs.EOF
Set rs2 = ("Select * From services where ID = " & rs("ID") & ";",)
Do While Not rs2.EOF
Response.Write "<font face=""Arial, Helvetica, sans-serif"" size=""1"" color=""green""><i>" & rs2("service") & "</i></font> " & vbcrlf
rs2.MoveNext
Loop
Response.Write "<br><br>"
If returncount >= 5 then
Response.Write "<a href=#0>Return to top</a><br><br><br>"
returncount = 0
End If
rs.MoveNext
Loop
rs.Close
set rs=nothing
rs2.Close
set rs2=nothing
Any help would be very helpful!
Thanks
$sql_test = mysql_query ("SELECT * FROM members, services WHERE members.service_id = services.service_id ORDER BY members.name ASC");
This would print out only those members that have services listed in the service table.
$sql_test = mysql_query ("SELECT * FROM members ORDER BY name ASC"); while($row = mysql_fetch_object($sql_test)){
echo "$row->name - $row->address";
// Get all the services for that member id
$member_services = mysql_query("SELECT * FROM member_services WHERE member_id = $row->member_id");
// Loop through and print those services from the query
while($serv_row = mysql_fetch_object($member_services)){
echo "$row->service<p />";
}
}
Of course, I don't know what your database structure is like, I'm just making up column names. Also, there is no formatting really ...
Hope it helps.
-sned
mem1:
washing
eating
mem2:
washing
drinking
...
etc
I wrote a beginning of an answer here:
[webmasterworld.com...]
Best regards
Michal Cibor
PS. Sned's way if functional, but takes a whole lot of server time (you may be doing tenths of sql queries), as with mine second way it's just one query and some more php coding.
BTW What kind of php is that "Do While Not"?