Log in

View Full Version : Resolved php missing duplicates



FrankieHouse
04-27-2009, 05:55 AM
Hi i'm sure there is any easy answer to this but hopefully someone can point me in the right direction.

I have an array with id numbers, sometimes there are duplicates in the array which is what i want. With these id numbers i'm doing a mysql query and pulling out an image link, the problem is that the results i get back from mysql aren't displaying the duplicates, so say i had 3 id 1's in the array i will only get back 1 image instead of the 3 if you get what i mean.

the code i have so far is this:


$addId = implode(",",$sessProduct);

$getSessionItems = mysql_query("SELECT * FROM products WHERE id IN ($addId)", $connection);
if(!$getSessionItems){
die("Database Query Failed: " . mysql_error());
}

while ($row = mysql_fetch_array($getSessionItems)){
echo $row["image"] . ", " . "</br>";
}


Can anyone tell me how i can get the duplicates as well?

Thanks

borris83
04-27-2009, 09:54 AM
No, that won't be possible with 'IN' operator in sql...

Instead, you can try this way:


foreach $sessProduct as $key
{
$getSessionItems = mysql_query("SELECT * FROM products WHERE id = ' $key' ", $connection);

if(!$getSessionItems)
{
die("Database Query Failed: " . mysql_error());
}


while ($row = mysql_fetch_array($getSessionItems))
{
echo $row["image"] . ", " . "</br>";
}

}

FrankieHouse
04-27-2009, 10:07 AM
Dude your a superstar thanks alot