mikes127 Posted December 5, 2006 Share Posted December 5, 2006 I have a problem with this pagination. I am able to go to the other pages but it does not display any query results. The first page is fine, but the other pages when I click on them theres nothing. I only see the page number on the rest of the pages. It does not show the query. Can someone please help. I been working on this for so long. Thanks![code]<?phpinclude('./header.php');if (isset($_GET['submit'])) {$message = NULL;// Check for Zip Codeif (empty($_GET['shop_zipcode'])) { $zc = FALSE; $message .= '<p>You forgot to enter the Zip Code!</p>'; } else { $zc = $_GET['shop_zipcode']; } if($zc) { //If everything is OK // Search database require_once('./mysql_connect.php'); // Connect to the database // sets how man results shown per page $limit = 5; $query_count = "SELECT count(*) FROM Shops WHERE ZipCode = $zc"; $result_count = mysql_query($query_count) or die("Error: " . mysql_error()); $totalrows = mysql_result($result_count, 0); if (empty($page)){ $page = 1; } echo "page ========$page"; $limitvalue = $page * $limit - ($limit); $query = "SELECT Shop_Name, Manager, Phone, Address, City, State, ZipCode,DATE_FORMAT(Date, '%M %d, %Y')FROM Shops WHERE ZipCode = $zc ORDER BY Shop_Name ASC LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if (mysql_num_rows($result) == 0){ echo("No Shops Available!"); } echo("<table>"); while($row = mysql_fetch_array($result)){ echo("<tr><td>"); echo "<tr><td><b>$row[0]</b></td></tr></tr><tr><td>$row[2]</td></tr><tr><td>$row[3]</td></tr><tr><td>$row[4], $row[5] $row[6]</td></tr><tr><td> </tr>"; } echo("</table>"); if($page != 1){ $pageprev = $page--; echo ("<a href=\"search.php?page=$pageprev\">PREV".$limit."</a> "); }else echo("PREV".$limit." "); $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"search.php?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo ($i." "); }else{ echo("<a href=\"search.php?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"search?page=$pagenext\">NEXT".$limit."</a>"); /* Since there are pages remaining, this outputs NEXT in link form. */ }else{ echo("NEXT".$limit); }} //mysql_free_result($result);}// Print message if there's oneif (isset($message)){ echo '<font color="red">', $message, '</font>';}echo "$totalrows";?> <form action="search.php" method="GET"><fieldset><legend>Enter a Zip Code:</legend><p><b>Shop Zip Code:</b> <input type="text" name="shop_zipcode" value="<?php if(isset($_GET['shop_zipcode'])) echo $_GET['shop_zipcode']; ?>" /></p></fieldset><div align="center"><input type="submit" name="submit" value="Search" /></div></form><!--End of Form --></body></html[/code] Link to comment https://forums.phpfreaks.com/topic/29579-php-with-form-odd-problem/ Share on other sites More sharing options...
Stooney Posted December 5, 2006 Share Posted December 5, 2006 im not gonna read it all, but i already know the prob. when you submit a form, it is 'posted' to the page you tell it. the variable are available to that page, but when you click on a link to another page, the variables are 'lost' so to say. each time to click a link you need some sort of way to 'send' the variables to it. you can do something like http://somewhere.com/?page=3&shop_zipcode=88006.you would also have to keep the shop_zipcode=$zip_code in all of your links. you could also use sessions. ex.[code]session_start();$_SESSION['zip_code']=$_GET['shop_zipcode'];[/code]then you would just change your script to get the zipcode from $_SESSION['zip_code'] instead of the $zc variable you're using. session variables will 'stick' through pages until you change them, destroy them, or the session ends. Link to comment https://forums.phpfreaks.com/topic/29579-php-with-form-odd-problem/#findComment-135706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.