Jump to content

pagination (where's page 2?)


sKunKbad

Recommended Posts

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 "&nbsp;";}
                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">&nbsp;</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
Share on other sites

Guest footballkid4
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
Share on other sites

[!--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
Share on other sites

Guest footballkid4
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
Share on other sites

[!--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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.