padams Posted May 26, 2008 Share Posted May 26, 2008 Not sure how to approach this. I am trying to display results from two tables, and the data I want from the second table is dependent on what comes out from the first one. I have a webpage that should display details and a thumbnail image for videos I'm selling, but as some videos have more than one thumbnail I have separated them into their own table. Each image has a videoID that links it back to a particular video from the video table. VideoID is the primary key for the videos table. Videos are organised by categories, so when I go to a particular category, all videos from that will be displayed. However, my query is going to the video table and selecting all those videos matching the selected category. This means that I can't query the images table at the same time as I don't initially know which videos will be displayed. How would I go about doing this? Code: $query="SELECT title, blurb FROM videos WHERE cat_id='".$catID."'"; Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted May 26, 2008 Share Posted May 26, 2008 Look into JOIN to join the two tables in the query Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 26, 2008 Share Posted May 26, 2008 Could you post your table structures? This is the best I could do from the information you gave SELECT v.title, v.blurb , i.image_from_image_table FROM videos v LEFT JOIN images i ON i.videoID = v.videoID WHERE cat_id='$catID' Quote Link to comment Share on other sites More sharing options...
padams Posted May 27, 2008 Author Share Posted May 27, 2008 That worked perfectly. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.