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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.