Jump to content


Photo

pagination (where's page 2?)


  • Please log in to reply
4 replies to this topic

#1 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 04 April 2006 - 04:14 AM

Actually what I have now is a link to page 2, but page two doesn't have any results on it.

<?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>";   
?>

Brian's Web Design - Temecula

Freedom is only available through death.

#2 Guest_footballkid4_*

Guest_footballkid4_*
  • Guests

Posted 04 April 2006 - 05:05 AM

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.

#3 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 04 April 2006 - 05:11 AM

[!--quoteo(post=361477:date=Apr 3 2006, 10:05 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 3 2006, 10:05 PM) View Post[/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?

Brian's Web Design - Temecula

Freedom is only available through death.

#4 Guest_footballkid4_*

Guest_footballkid4_*
  • Guests

Posted 04 April 2006 - 06:27 AM

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.

#5 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 04 April 2006 - 05:38 PM

[!--quoteo(post=361487:date=Apr 3 2006, 11:27 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 3 2006, 11:27 PM) View Post[/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!
Brian's Web Design - Temecula

Freedom is only available through death.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users