Re: Multipe Tables, Single Query Problem

From: Date: Tue, 19 Jun 2001 03:19:27 +0000
Subject: Re: Multipe Tables, Single Query Problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-54317@lists.php.net to get a copy of this message
At 01:57 PM 6/06/2001, you wrote:
Hi all, I have three tables in my (mysql) database: videos - ID, title, description, etc.. links - ID, videoID, actorID actors - ID, name, dateofbirth, gender, etc... what i need to do is return a particular video and all it's staring actors with just one query returning just one row, ie. with all the actor names in one field... is this possible? or do i have to get the video data first and then the actors separately?
$count=0; $query = "select actors.*, videos.* from actors, videos where videos.ID = '$ID' and videos.ID=actors.actorID order by actors.name"; $result=mysql_query($query); while (mysql_fetch_array($result)) { if ($count<0) echo "Movie Title: $display[title] - $display[desc]<P>"; echo "Actor: $display[name] - DOB: $display[dateofbirth] etc etc<BR>"; $count++; } This is how I do it anyway. Make an incrementing value, and the if ($count<0) line basically says to display the title once, and skip it for every other entry. Chances are the query would need tweaking but the principle is there to get data from all needed tables in 1 query, then set the loop to display the needed data from the 1 query. There is probebly a more efficient way of doing it, but thats how I do it anyway. Chris

« previous php.general (#54317) next »