co.ador Posted March 1, 2010 Share Posted March 1, 2010 * For pagination to work, I need pass on the original search terms to the next page. I think http_build_query could be used and append this to the page links. * Some another person opinion said that There is no need to count the number of stores in the script I have, I need to count the number that match the search terms. This is why there are more links that required. And that's a good an idea on what could be happening. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/193835-need-some-help-with-passing-the-orignal-search-terms-in-a-pagination-script/ Share on other sites More sharing options...
Psycho Posted March 1, 2010 Share Posted March 1, 2010 Save the search terms to session variables. Quote Link to comment https://forums.phpfreaks.com/topic/193835-need-some-help-with-passing-the-orignal-search-terms-in-a-pagination-script/#findComment-1020156 Share on other sites More sharing options...
Psycho Posted March 2, 2010 Share Posted March 2, 2010 OK, you decided to respond to me through IM for some reason, but I'll respond here. You have not provided any code, so I can't give specifics, but I'll give you the basics. You apparently already have some code that determines whether the user has submitted a search query and filters the results for the pagination accordingly. When you take that data to run your query you want to also save the data to session variables. But, you will also need to clear any existng variables when the user changes the query. Here is an example: session_start(); $whereClauseAry = array(); $recordsPerPage = 10; $page = 1; if (isset($_POST)) { //User has submitted new criteria //Reset the saved criteria fields $_SESSION['restaurant_query'] = array(); $name = trim($_POST['name']); $zip = trim($_POST['zip']); if(!empty($name)) { $whereClauseAry[] = "`name` = '" . mysql_real_escape_string($name) . "'"; $_SESSION['restaurant_query']['name'] = $name; } if(!empty($zip)) { $whereClauseAry[] = "`zip` = '" . mysql_real_escape_string($zip) . "'"; $_SESSION['restaurant_query']['zip'] = $zip; } } elseif (isset($_GET['page'])) { //User has selected a new page for the current criteria //Get the saved criteria values if (isset($_SESSION['name'])) { $whereClauseAry[] = "`name` = '" . mysql_real_escape_string($_SESSION['name']) . "'"; } if (isset($_SESSION['zip'])) { $whereClauseAry[] = "`zip` = '" . mysql_real_escape_string($_SESSION['zip']) . "'"; } $page = (int) $_GET['page']; } $whereClauseStr = ''; if (count($whereClauseAry)>0) { $whereClauseStr = "WHERE " . implode(' AND ', $whereClauseAry); } //Run the query for the current page of the current criteria $limitStart = ($page-1) * $recordsPerPage; $query = "SELECT * FROM restaurants {$whereClauseStr} LIMIT {$limitStart}, {$recordsPerPage}"; Quote Link to comment https://forums.phpfreaks.com/topic/193835-need-some-help-with-passing-the-orignal-search-terms-in-a-pagination-script/#findComment-1020208 Share on other sites More sharing options...
co.ador Posted March 5, 2010 Author Share Posted March 5, 2010 Thank you very much! I have adapt it to my script and it works. Quote Link to comment https://forums.phpfreaks.com/topic/193835-need-some-help-with-passing-the-orignal-search-terms-in-a-pagination-script/#findComment-1022014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.