Forum Moderators: coopster

Message Too Old, No Replies

new to php

asp to php

         

spotty

8:55 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I have 2 tables. One with member info
The other table has services in which the member has submitted.
I've done a simple loop through the members table.

// 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>&nbsp;&nbsp;" & 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

Sarah Atkinson

9:09 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Maybe it's just me and getting late in the day but I didn't understand a word you posted (exept for the mysql statements)

Burner

9:14 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



If your member table has a record in the member table signifying what services they have in the services table, you can use something like:

$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.

spotty

9:29 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



That sorta works, but the problem is that it now lists the member as many times as they have services.

Let's say that member1 has 2 services
washing clothes
eating fish

It will list it like this

member1
washing clothes
member1
eating fish

sned

9:41 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



You might be able to do something like this:

$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

mcibor

9:41 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think that what you want is a tree like structure:

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"?

spotty

9:48 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



do while not is from the asp code.
I'll play with this tonight, hopefully get it working.

thanks for the quick response.

jatar_k

9:54 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld spotty,

don't let them pick on ya ;)