Jump to content

While() is display 30 of the same items..i only need it to display once


Recommended Posts

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!";
   }
?>

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.

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.