pagination search term carry over to next page

Discussion in 'PHP' started by lektrikpuke, Feb 24, 2008.

  1. #1
    Hi y'all,

    I'm working with a script for pagination of search results. On the first page it shows the correct amount of results, and it shows the correct number of links (for pages). However, when I go to the next page (or any page as returned by the script) it says there are no search results - basically it did not transfer/keep the search keyword (even though it's url encoded in the link).

    How do I get the keyword (for the search) to transfer to the next page.

    How about a good tutorial for pagination. I've looked at a couple and I'm really close to making this work.
     
    lektrikpuke, Feb 24, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Post your code. I don't feel like guessing.
     
    nico_swd, Feb 24, 2008 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    Nico_swd, thanks for responding so quickly, but I finally woke up and got over that hurdle. I guess it was the threat of having to post my code (and subsequent embarrassment) that motivated me. =)
     
    lektrikpuke, Feb 24, 2008 IP
  4. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #4
    $Nav="";
    If($page > 1) {
    $Nav .= "<A HREF=\"search_results.php?page=" . ($page-1) . "&SearchString=" .urlencode($SearchString) . "\"><< Prev</A>";
    }
    For($i = 1 ; $i <= $NumberOfPages ; $i++) {
    If($i == $page) {
    $Nav .= "<B>$i</B>";
    }Else{
    $Nav .= "|<A HREF=\"search_results.php?page=" . $i . "&SearchString=" .urlencode($SearchString) . "\">$i</A>";
    }
    }
    If($page < $NumberOfPages) {
    $Nav .= "<A HREF=\"search_results.php?page=" . ($page+1) . "&SearchString=" .urlencode($SearchString) . "\">| Next >></A>";
    }

    Echo "<BR><BR>" . $Nav;

    Is the search string passed to the next page (and picked up by the script) by the searchstring = ... ? (which seems to me to be what's happening), or is it a global that stays active till the browser is closed? I'm just trying to wrap my head around this. I only ask because I've seen code that doesn't include the searchstring = as part of the url.
     
    lektrikpuke, Feb 24, 2008 IP
  5. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #5
    Ok, looked up urlencode. Thanks for your help any way.
     
    lektrikpuke, Feb 24, 2008 IP