Help on keeping an variable value coming from the url on

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



?>

Append the parameters to your paging links, and use $_REQUEST instead of $_POST at the top of the script.

i am trying to adapt what you have told me so far I have done this

in page1.php is the form I have appended like this

<form name="frmSearch" class="abajo" action="indexpagination.php?strZipCode=<?php echo $strZipCode; ?>&strName=<?php echo $strZipCode; ?>&strState=<?php echo $strState; ?>"  method="post">

in page indexpagination.php I get the value with the $_REQUEST global variable


    $strName = isset($_REQUEST['frmSearch']['name'])?mysql_real_escape_string($_REQUEST['frmSearch']['name']):'';
    $strZipCode = isset($_REQUEST['frmSearch']['zipcode'])?mysql_real_escape_string($_REQUEST['frmSearch']['zipcode']):'';
    $strState = $_REQUEST['frmSearch']['state']/*)*/;
    $arrFoodTypes = isset($_REQUEST['frmSearch']['food_types'])?mysql_real_escape_string($_REQUEST['frmSearch']['food_types']):array();
    $arrOfferings = isset($_REQUEST['frmSearch']['offerings'])?mysql_real_escape_string($_REQUEST['frmSearch']['offerings']):array();

Then get this comparinson at the query

$query4 = "SELECT state, zip, county
FROM restaurants 
WHERE 
(zip='$strZipCode')";

and the paging links are appended like this

echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1&strZipCode=".  $strZipCode . "' ><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
   echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&strZipCode=".  $strZipCode . "'><</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 http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
         echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&strZipCode=".  $strZipCode . "'>$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 http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
   echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&strZipCode=".  $strZipCode . "'>></a> ";
   // echo forward link for lastpage http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
   echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&strZipCode=".  $strZipCode . "'>>></a> ";
} // end if

 
?> 

The problem stills persist. When link on one of the paging links it links the user to the second page of rows and the url is

http://localhost/stores/indexpagination.php?currentpage=2&strZipCode=01561

and it will still display this

ounty:0 State: Zip Code:

Instead of:

County:Woscester
State:MA
Zip Code:01561

The this display above is this script

 $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>';

echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&strZipCode=".  $strZipCode . "'>>></a> ";

Are you asking why the above produces this

http://localhost/stores/indexpagination.php?currentpage=2&strZipCode=01561

instead of

http://localhost/stores/indexpagination.php?currentpage=2&strZipCode=01561&county=Woscester&state=MA

as for your question Hash I have tried


echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1&strZipCode=".  $strZipCode . "&strState=" $strState"&strName"$strName"'>"

echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1&strZipCode=".  $strZipCode . "&strState=". $strState. "&strName". $strName. "'>"

echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1&strZipCode=".  $strZipCode . "&strState=" echo $strState; "&strName"echo $strName; "'>" 

without not results Right now the only variable that has a value is strZipCode becuase it is a numeric value. The other two are string and are not displaying in the URL becuase of the parsin. The third option doesn’t throw any errors but the variable will appear as empty in the url. Need to say the above links are the paging links…

Any suggestions on reading…
i am pulling my hair here.

Only one of those is even valid php. The fact you even tried the first or third ones indicates that for suggested reading you might want to buy Kevin’s book, or some other intro to php and mysql.

I mean no offence by this, sorry, but what you are doing is beyond your level, and you will just end up bald from all the hair pulling.

you do trying to offend my intelligance and I won’t take that… Lol look at what I have come up with and I did it by myself

 if(!empty($strZipCode)){
  $query4 = "SELECT state, zip, county
FROM restaurants 
WHERE 
(zip= '$strZipCode')"; 
echo $query4;
$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>';
			 }
			 else {
			 $query4 = "SELECT state, zip, county
FROM restaurants 
WHERE 
zip= ".  $_GET['strZipCode']. ""; 
echo $query4;
$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>';
			 }

In the pagination links I have append this…

echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&strZipCode= ". $strZipCode . "'>$x</a> ";

Yes!!!

Hash let me know when you need assistance. LOL

I am getting it thank you guys.

I suppose hash was referring to Kevin Yank’s book? I wish every freelance coder on GFA had a copy if that makes them any better, I got bald because of this about 3 years ago… it’s been mostly JSP ever since :frowning: