SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Tricky pagination problem

    Hello all,

    I have a site with pagination from a mysql query which works fine, but have this particular query result that is very tricky to paginate since I have no way of knowing which results are returned. It goes like this:

    I grab an array of ids first from a query (the query is inmaterial), then I do another query and only show the images if the ids in the second query are NOT in the first one:
    PHP Code:
    while ($row mysql_fetch_assoc($getallRes)) {
            if (!
    in_array($row['id'], $votedImage)) {    
               
    $title $row['title'];
               
    $imageId $row['id'];    
                   
               
    // echo title, etc with some formatting here        
            
    }

        } 
    Since I have no way of knowing how many rows will actually show here, my pagination code does not work. I should add that the query can also be restricted by search criteria but that shouldn't affect this issue.

    Can anyone think of a way to paginate this?

    Thanks.
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Can't you add a
    Code MySQL:
    WHERE id NOT IN (list of values from the first query)
    to your query? That way it'll return only the images you will show, and the pagination will work again.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm ashamed to say that it didn't even occur to me to do that!

    Sometimes we just want to do things a certain way and that's all we can see.

    How does it expect the data if I try this? comma separated ids or what?
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    yes: NOT IN (1, 2, 3, 4, ...)

  5. #5
    SitePoint Evangelist
    Join Date
    May 2002
    Location
    Barcelona, Spain
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bona sera Guido,

    You are a @#$%ing genius! This did the trick wonderfully and saved me about 50 lines of crazy code I was using. Now, if only I'd asked sooner it would have saved me about 2 days of agony! I just never thought of it, how dumb on my part.

    Thanks a million.
    Used to prefer PHP.
    Now I prefer Maya but stuck with PHP
    bruji.com


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
  •