sKunKbad Posted April 4, 2006 Share Posted April 4, 2006 Actually what I have now is a link to page 2, but page two doesn't have any results on it.[code]<?php include("./includes/genesis.php"); $value1 = "$_POST[city]"; echo "<h2>Christian Churches in $city</h2>"; if (!isset($_GET['page'])){ $page = 1; } ELSE { $page = $_GET['page']; } $max_results = 5; $from = (($page * $max_results) - $max_results); if ($value1 == "All Cities") {$sql = mysql_query("SELECT * FROM localdirectory WHERE type = 'church' LIMIT $from, $max_results"); } ELSE {$sql = mysql_query("SELECT * FROM localdirectory WHERE city = '$value1' AND type = 'church' LIMIT $from, $max_results"); } while($row = mysql_fetch_array($sql)) { extract ($row); echo "<div class=\"sponsor\">"; if($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this church is a site sponsor\"/>";} else {echo " ";} echo "</div>"; echo "<div class=\"listing\">"; echo "<strong>$name</strong>"; if($address != ""){echo "<br/>\n$address";} if($city != ""){echo "<br/>\n$city",", ";} if($st != ""){echo "$st"," ";} if($zip != ""){echo "$zip";} if($teleNumber != ""){echo "<br/>\n$teleNumber";} if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";} if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";} echo "</div>\n";?><div class="hrule76"> </div><?php echo "\n"; } echo "<p><a href=\"http://www.iamsentme.com/directory.php\">Go Back</a></p>"; if ($value1 == "All Cities"){$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'church'"),0);}ELSE{$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'church' AND city ='$value1'"),0);}$total_pages = ceil($total_results / $max_results); echo "<center><br/><strong>Page<br />";if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; }} if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";}echo "</strong></center>"; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/6540-pagination-wheres-page-2/ Share on other sites More sharing options...
Guest footballkid4 Posted April 4, 2006 Share Posted April 4, 2006 The reason you aren't seeing any results is because you are trying to access a $_POST variable, which is unset after you navigate away from the page that the data was posted to. You can urlencode() it and pass it into the querystring, or use sessions to store the information. Link to comment https://forums.phpfreaks.com/topic/6540-pagination-wheres-page-2/#findComment-23732 Share on other sites More sharing options...
sKunKbad Posted April 4, 2006 Author Share Posted April 4, 2006 [!--quoteo(post=361477:date=Apr 3 2006, 10:05 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 3 2006, 10:05 PM) [snapback]361477[/snapback][/div][div class=\'quotemain\'][!--quotec--]The reason you aren't seeing any results is because you are trying to access a $_POST variable, which is unset after you navigate away from the page that the data was posted to. You can urlencode() it and pass it into the querystring, or use sessions to store the information.[/quote]Well, I have absolutely no idea how to accomplish what you are saying to do, but I will start looking into it. Is one way easier than the other? Sessions vs. urlencode() pass to querystring? Link to comment https://forums.phpfreaks.com/topic/6540-pagination-wheres-page-2/#findComment-23733 Share on other sites More sharing options...
Guest footballkid4 Posted April 4, 2006 Share Posted April 4, 2006 Sessions would be easier, and safer to work with if this is going to be a critical project. If it's just a simple search feature then I would suggest using $_GET. If you don't need to use sessions, simply don't do it...it's just more server load. If you are going to use sessions for this, be sure that your php.ini configuration is setup to unset them after they exit the browser...otherwise users might try to come back and search...and then see the same results as their last search. Link to comment https://forums.phpfreaks.com/topic/6540-pagination-wheres-page-2/#findComment-23741 Share on other sites More sharing options...
sKunKbad Posted April 4, 2006 Author Share Posted April 4, 2006 [!--quoteo(post=361487:date=Apr 3 2006, 11:27 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 3 2006, 11:27 PM) [snapback]361487[/snapback][/div][div class=\'quotemain\'][!--quotec--]Sessions would be easier, and safer to work with if this is going to be a critical project. If it's just a simple search feature then I would suggest using $_GET. If you don't need to use sessions, simply don't do it...it's just more server load. If you are going to use sessions for this, be sure that your php.ini configuration is setup to unset them after they exit the browser...otherwise users might try to come back and search...and then see the same results as their last search.[/quote]I fixed it! I just changed my form method to GET, and added &city=$value1 in back of ?page=$prev, ?page=$i, and ?page=$next.Thanks for you help, now I have a new problem! Link to comment https://forums.phpfreaks.com/topic/6540-pagination-wheres-page-2/#findComment-23868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.