A JM Posted September 29, 2009 Share Posted September 29, 2009 I'm having a problem getting a variable to pass from one page to another. I'm using pagination on my site and my goal is to simply pass the variable "pagination=1" once when paging to or from a page on my site. What's happening is the variable is being added each time I page to another page for example I changed pages 3 times and this is what is now being passed. http://xxx.php?pageNum_rstclaimcue=1&totalRows_rstclaimcue=100&pagination=1&pagination=1&pagination=1 I've attached the relevant code from the page and hopefully someone can help me solve this. Thanks for any help. A JM, ... $editFormAction = $_SERVER['PHP_SELF']; //when form is submitted recordset will get adjusted for sorting and dates, etc. $currentPage = $_SERVER["PHP_SELF"]; $maxRows_rstclaimcue = 15; $pageNum_rstclaimcue = 0; if (isset($_GET['pageNum_rstclaimcue'])) { $pageNum_rstclaimcue = $_GET['pageNum_rstclaimcue']; } $startRow_rstclaimcue = $pageNum_rstclaimcue * $maxRows_rstclaimcue; mysql_select_db($database_maxdbconn, $maxdbconn); if ( $_POST['querysubmitted'] == 1) { //convert the date format from m/d/y => y-d-m list($month, $date, $year) = explode("/", $_POST['datefrom']); $queryfrom = $year . '-' . $month . '-' . $date; list($month, $date, $year) = explode("/", $_POST['dateto']); $queryto = $year . '-' . $month . '-' . $date; $query_rstclaimcue = "SELECT c.*, u.firstname AS data_first, u.lastname AS data_last, h.firstname AS adj_first, h.lastname AS adj_last FROM claimcue c LEFT JOIN users u ON(c.data_id = u.id) LEFT JOIN users h ON(c.adj_id = h.id) WHERE c." . $_POST['runqueryname'] . " LIKE '%" . $_POST['criteria'] . "%' AND c.new_timestamp BETWEEN '" . $queryfrom . "' AND '" . $queryto . "' ORDER BY c." . $_POST['runqueryname'] . " ASC"; print_r("submitted" . $query_rstclaimcue); }else{ //default sql $query_rstclaimcue = "SELECT * FROM claimcue WHERE chk_new=2"; print_r("default" . $query_rstclaimcue); } $query_limit_rstclaimcue = sprintf("%s LIMIT %d, %d", $query_rstclaimcue, $startRow_rstclaimcue, $maxRows_rstclaimcue); $rstclaimcue = mysql_query($query_limit_rstclaimcue, $maxdbconn) or die(mysql_error()); $row_rstclaimcue = mysql_fetch_assoc($rstclaimcue); if (isset($_GET['totalRows_rstclaimcue'])) { $totalRows_rstclaimcue = $_GET['totalRows_rstclaimcue']; } else { $all_rstclaimcue = mysql_query($query_rstclaimcue); $totalRows_rstclaimcue = mysql_num_rows($all_rstclaimcue); } $totalPages_rstclaimcue = ceil($totalRows_rstclaimcue/$maxRows_rstclaimcue)-1; $queryString_rstclaimcue = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_rstclaimcue") == false && stristr($param, "totalRows_rstclaimcue") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_rstclaimcue = "&" . htmlentities(implode("&", $newParams)); } } $queryString_rstclaimcue = sprintf("&totalRows_rstclaimcue=%d%s", $totalRows_rstclaimcue, $queryString_rstclaimcue)."&pagination=1"; ?> Link to comment https://forums.phpfreaks.com/topic/175916-solved-need-some-pagination-help/ Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 The final line of your code adds "&pagination=1" to your URL, and it will be ran every time. Since before that you also extract out all the old parameters from the original query string, this will obviously keep adding it every time you change page. One solution would be to only add "&pagination=1" if it's not already a parameter. Something like... <?php if(!in_array("pagination=1", $params)) { // add &pagination=1 } ?> Link to comment https://forums.phpfreaks.com/topic/175916-solved-need-some-pagination-help/#findComment-926975 Share on other sites More sharing options...
A JM Posted September 29, 2009 Author Share Posted September 29, 2009 Thanks that helped solve the problem. A JM, Link to comment https://forums.phpfreaks.com/topic/175916-solved-need-some-pagination-help/#findComment-927349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.