Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    4
    Thanked 0 Times in 0 Posts

    query on submit (search and pagination problem)

    I have a form
    <select>
    <option value="">Select color</option>
    <option value="black">black</option>
    <option value="red">red</option>
    </select>

    <select>
    <option value="">Select size</option>
    <option value="one">two</option>
    <option value="two">two</option>
    </select>

    <input type="submit" value="Submit" name="submit" />




    PHP Code:
    $color $_GET['color'];
    $size $_GET['size'];

    (...)

    $query "SELECT * FROM table WHERE color LIKE  '%$color%'  AND  size LIKE '%$size%' LIMIT $start, $per_page ";

    (...) 

    and the search link is something like this:
    http://www.domain.com/file.php?color...&submit=Submit

    When paginating the results, when I click to page2 I get page2 with all the results from db (not the color and size selected on the search) and the link is something like this www.domain.com/file.php?page=2

    How can I resolv this problem?
    I searched and read about this problem for a while... but I can't find the solution.


    Now I think to do a verification to run the query just when I click the submit button.

    Something like this

    <input type="hidden" name="searching" value="yes" />

    and

    if ($searching =="yes")

    .


    Any other ideea?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You've simply lost your querystring. Where are you building the pagination links?

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have one more fields that I select and send me to different files.
    So, I have file1.php, file2.php, file3.php.

    I use include for the top part of page with the search form. So the search form is on every page.

    The pagination is on file1.php (file2.php, and file3.php).
    This are the results page. (Sorry if you asked something else).

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah, where's the code for making the pagination links?

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    4
    Thanked 0 Times in 0 Posts
    PHP Code:
        if($pages >= && $page <= $pages){
                    for (
    $x=1;  $x<=$pages$x++){
                         
    $pagination .= ($x == $page) ? '<strong>' $x '</strong> ' '<a href="?page=' .$x'"> ' $x '</a> ';
                        }
                    
            } 
    this is the code.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    $x only represents the page number. You do not have enough information to pass along to other pages to use the search. Use this (you can unset anything from post you don't need in the $aQS):
    PHP Code:
    $aQS $_GET;
    if (
    $pages >= && $page <= $pages)
    {
        for (
    $x 1$x <= $pages; ++$x)
        {
            
    $aQS['page'] = $x;
            
    $sQS http_build_query($aQS);
            
    $pagination .= ($x == $page) ? '<strong>' $x '</strong> ' sprintf('<a href="%s">%s</a>'$sQS$x); 
        }


  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    4
    Thanked 0 Times in 0 Posts
    still dosn't work

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What is the querstring passed by the links?


  •  

    Posting Permissions

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