flowingwindrider Posted July 18, 2007 Share Posted July 18, 2007 My last thread on pagination was getting very confusing to read due to the fact that I had completely changed scripts during the course of the thread and confusion was developing as to which script I needed help on. I hope I'm not breaking any posting rules, it seemed that simply starting a new thread was the lease confusing way to proceed. Anyway, below is the script that I am working with at the moment. I returns no errors, but when you follow the supposedly paginated links at the bottom they don't take you anywhere. I'm not convinced that the $page, $pageprev, and $pagenext variables are functioning properly, but I can't figure out why not, but for all I know it could be something else wrong. Any thoughts? <?php @$dbh = mysql_connect("localhost", "user", "password") or die ("Error Connecting: " . mysql_error()); @mysql_select_db("bransone_classifieds") or die ("Can't find database: " . mysql_error()); $limit = 10; $query_count = "SELECT COUNT(Ad_Id) AS Total FROM employment"; $result_count = mysql_query($query_count) or die ("Error in query" . mysql_error()); $fetch_result = mysql_fetch_assoc($result_count) or die ("Error in query" . mysql_error()); $totalrows = $fetch_result['Total']; if(!$page) { $page = 1; } echo ("\$page starts as $page<br><br>"); $limitvalue = $page * $limit - ($limit); $query = "SELECT Ad_Id, `Date`, Type_Job FROM employment ORDER BY `Date` DESC, Ad_Id DESC LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0) { echo ("There are currently no ads in this category."); } while($row = mysql_fetch_array($result)) { $ad_id = $row['Ad_Id']; $date = $row['Date']; $type = $row['Type_Job']; echo "$ad_id - $date - $type<BR><BR>"; } if($page != 1) { $pageprev = $page--; echo("<a href=\"test3.php?page=$pageprev\">Previous ".$limit." Listings - </a>"); } else { echo("Previous ".$limit." Listings - "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++) { if($i == $page) { echo($i." "); } else { echo("<a href=\"test3.php?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0) { if($i == $page) { echo($i." "); } else { echo("<a href=\"test3.php?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0) { $pagenext = $page++; echo("<a href=\"test3.php?page=$pagenext\">Next ".$limit." Listings</a>"); } else { echo(" - Next ".$limit." Listings"); } mysql_close($dbh); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.