jeger003 Posted January 31, 2009 Share Posted January 31, 2009 i finally figured out how to JOIN two tables and now the it goes through but it displays the same item 30 times like: car car car car car house house house house house it would display car 30 times and house 30 times what am i doing wrong? here is my code <?php $id = 'listings.id'; $query_image = mysql_query("SELECT listings_urls.listings_id,listings_urls.thumb_url,listings.title,listings.image FROM listings_urls,listings WHERE listings_urls.listings_id = $id AND listings.live = 1") or die(mysql_error()); $num = mysql_num_rows($query_image); if($num > 0) { while ($fetch = mysql_fetch_array($query_image) ) { if($fetch['image']== 1) { echo "<img src='/".$fetch['thumb_url']."'><br>"; echo "<br>".$fetch['title']; } else { echo "no image to display"; } } } else { echo "no items found!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143308-while-is-display-30-of-the-same-itemsi-only-need-it-to-display-once/ Share on other sites More sharing options...
Snart Posted January 31, 2009 Share Posted January 31, 2009 You're not linking both tables. There should be something like the following in your WHERE clause: listings_urls.id = listings.id Quote Link to comment https://forums.phpfreaks.com/topic/143308-while-is-display-30-of-the-same-itemsi-only-need-it-to-display-once/#findComment-751599 Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 You created a cartesian join. The code below should fix that. "SELECT lu.listings_id,lu.thumb_url,li.title,li.image FROM listings_urls lu,listings li WHERE lu.listings_id = li.listings_id AND lu.listings_id = $id AND listings.live = 1" The above is assuming both have a field called "listings_id" that you can relate the two tables together. Quote Link to comment https://forums.phpfreaks.com/topic/143308-while-is-display-30-of-the-same-itemsi-only-need-it-to-display-once/#findComment-751600 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.