Php and MySQL Querys using values in other tables -
so i'm trying fetch of user_id's users-events table event_id equal passed in variable (let's it's 2 now.)
in database there 2 id's registered event_id 1 , 2.
this code returns first of these values. feel need incorporate first query while loop dont know how go it.
any appriciated!
function showregisteredplayers($id){ $eventq = mysql_fetch_assoc(mysql_query("select user_id `users-events` event_id = '".$id."'")); $rosterq = mysql_query("select username `users` `user_id` = '".$eventq['user_id']."'"); while($player = mysql_fetch_assoc($rosterq)){ echo(" <tr> <td>".$player['username']."</td> </tr> "); } }
use sub query kill first one.
select username `users` `user_id` in ( select user_id `users-events` event_id = 5 )
rest fine, looping on second result set should do. unless have large number of records, there should not considerable performance degradation use of in
otherwise can optimize query.
5 example, use $id
there correctly.
Comments
Post a Comment