Jump to content

Is there a way to combine these 3 queries into one?


tommyda

Recommended Posts

Hi I have 3 tables, one with a list of genres, one with movie listings and one to assign genres to the movie listings.

 

Genres

 

id, name

 

Videolistings

 

id, name, title, img

 

Assign

 

type, typeid, vlid

 

 

I would l to pull the list of genres and all the movie listing details in the same query, I have managed to achieve this but only using 3 separate queries but it looks messy and I know there must be a more efficient way of doing this.

 

currently I am selecting all the rows from the assign table where type=genre and vlid=1 then

in a while loop I am selecting * from videolistings to get the info and selecting name from genres.

<?php
$getgenrelist=mysql_query("SELECT * FROM assign WHERE type='genre' AND typeid='$vlid'") or die(myslq_error());

while($row = mysql_fetch_array($getgenrelist))
{
$getvideo = mysql_query("SELECT * FROM videolistings WHERE id ='$row[vlid]' ");
$video = mysql_fetch_array($getvideo);

$getgenre = mysql_query("SELECT name FROM genres WHERE id = '$row[typeid]'")
while($genre= mysql_fetch_array($getgenre))
{
$genres.=$genre['name'];
};
echo $Video name $img $genres.......
};

};
?>

 

So if anyone can help that would be much appreciated.

 

Thanks

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.