co.ador Posted December 17, 2009 Share Posted December 17, 2009 I am using a form in page 1. When I fill the form and click summit it passes several variable values pickup in page 2, page 2 uses a pagination script and the first time it display the data coming from the form, displaying the values but when i click in the second page in the pagination rows of numbers then the variable coming from page 1 to page 2 turns off only for the query of the three used in the script below WHERE (zip= '$strZipCode') on the very top of the script right below where zip=$strZipCode variable coming from page 1 form is extracted. in this case the variable $strZipCode will activate the query below so, if that variable value is not through then the query won't display it's fields zip, state etc... It does = to false when users goes through pagination in page 2. It seems like the value of $strZipCode is lost. How can I still maintain the variable value through pagination? what is happening in this query that the variable $strZipCode is not passing true when users paginate through when looking for more set of rows results? Page 2 <?php <?php $strName = isset($_POST['frmSearch']['name'])?mysql_real_escape_string($_POST['frmSearch']['name']):''; $strZipCode = isset($_POST['frmSearch']['zipcode'])?mysql_real_escape_string($_POST['frmSearch']['zipcode']):''; $strState = $_POST['frmSearch']['state']/*)*/; $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?mysql_real_escape_string($_POST['frmSearch']['food_types']):array(); $arrOfferings = isset($_POST['frmSearch']['offerings'])?mysql_real_escape_string($_POST['frmSearch']['offerings']):array(); ?> $query4 = "SELECT state, zip, county FROM restaurants WHERE (zip= '$strZipCode')"; $result = mysql_query($query4); $arrstate = mysql_fetch_array($result); echo '<div class="information"><label>County:</label> <div>'. $arrstate['county']. '</div> <label>State:</label> <div>'. $arrstate['state']. '</div> <label>Zip Code:</label> <div>'. $arrstate['zip']. '</div></div> <br><br>'; $sql = "SELECT COUNT(*) FROM restaurants"; $result = mysql_query($sql) or trigger_error(mysql_error()); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 6; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT zip, state, address FROM restaurants LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['zip'] . " : " . $list['state'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if ?> Link to comment https://forums.phpfreaks.com/topic/185521-help-on-keeping-an-variable-value-coming-from-the-url-on/ Share on other sites More sharing options...
co.ador Posted December 17, 2009 Author Share Posted December 17, 2009 Have decided to post the code again since it was very hard to read in the first post. <?php <?php $strName = isset($_POST['frmSearch']['name'])?mysql_real_escape_string($_POST['frmSearch']['name']):''; $strZipCode = isset($_POST['frmSearch']['zipcode'])?mysql_real_escape_string($_POST['frmSearch']['zipcode']):''; $strState = $_POST['frmSearch']['state']/*)*/; $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?mysql_real_escape_string($_POST['frmSearch']['food_types']):array(); $arrOfferings = isset($_POST['frmSearch']['offerings'])?mysql_real_escape_string($_POST['frmSearch']['offerings']):array(); $query4 = "SELECT state, zip, county FROM restaurants WHERE (zip= '$strZipCode')"; $result = mysql_query($query4); $arrstate = mysql_fetch_array($result); echo '<div class="information"><label>County:</label> <div>'. $arrstate['county']. '</div> <label>State:</label> <div>'. $arrstate['state']. '</div> <label>Zip Code:</label> <div>'. $arrstate['zip']. '</div></div> <br><br>'; $sql = "SELECT COUNT(*) FROM restaurants"; $result = mysql_query($sql) or trigger_error(mysql_error()); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 6; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT zip, state, address FROM restaurants LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['zip'] . " : " . $list['state'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if ?> Link to comment https://forums.phpfreaks.com/topic/185521-help-on-keeping-an-variable-value-coming-from-the-url-on/#findComment-979487 Share on other sites More sharing options...
JAY6390 Posted December 17, 2009 Share Posted December 17, 2009 Firstly, this is not allowed <?php <?php Hopefully you've just edited out some code and not remembered to delete one of those As for the problem you're having, why not save the value in a session variable? Link to comment https://forums.phpfreaks.com/topic/185521-help-on-keeping-an-variable-value-coming-from-the-url-on/#findComment-979493 Share on other sites More sharing options...
co.ador Posted December 17, 2009 Author Share Posted December 17, 2009 that was a typo... Link to comment https://forums.phpfreaks.com/topic/185521-help-on-keeping-an-variable-value-coming-from-the-url-on/#findComment-979495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.