Results 1 to 3 of 3

Thread: php missing duplicates

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default php missing duplicates

    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:
    PHP Code:
    $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
    Last edited by FrankieHouse; 04-27-2009 at 10:09 AM.

  2. #2
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    No, that won't be possible with 'IN' operator in sql...

    Instead, you can try this way:

    Code:
    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>";
            }  
    
     }

  3. The Following User Says Thank You to borris83 For This Useful Post:

    FrankieHouse (04-27-2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Dude your a superstar thanks alot

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •