How get post value in pagination

前端 未结 2 606
悲哀的现实
悲哀的现实 2021-01-27 06:03

I am working on search functionality with pagination in php.Below is my code but whenever I click on next link the search query is not taking variable which is passed through PO

2条回答
  •  佛祖请我去吃肉
    2021-01-27 06:12

    There are a couple problems in your code.

    First:

    You are using the $_GET variable incorrectly. You have $_GET{'page'}, but you should be using it the same way as the$_POST variable, like this: $_GET['page']

    Second:

    You are interpreting the idea of POSTing and clicking links incorrectly. What you need to make with your next and previous buttons are a hidden form that has all the other variables you need. For example, the simplest way that won't involve changing a lot of your other code:

    if( $page > 0 & $left_rec > $rec_limit)
    {
        $last = $page - 2;
        // Previous button form
        echo "
    "; echo ""; // This will be a field that saves information but won't appear on the page (though a user could see it if they view source) echo ""; echo "
    "; echo " | "; // The delimiting character you were using, you'll need to style the input type='submit's to look more like a link if that's what you are going for // Next button form echo "
    "; echo ""; // This will be a field that saves information but won't appear on the page (though a user could see it if they view source) echo ""; echo "
    "; }

    This method will keep your variables in the request. Using a link essentially resets the $_POST variable. There are a ton of other possible solutions, but this is one will require the least amount of work to modify your example.

提交回复
热议问题