EchoFool Posted February 18, 2008 Share Posted February 18, 2008 Me again... i am wondering if some one could help explain how i can add to my pagination. It works a treat... only I only know how to create a "Next Last" "First Previous" option.. But what i am looking for is: First Previous 1 2 3 [4] 5 6 Next Last (Assuming.. that in this situation.. the user is on page 4.) I do not know how to make numbered pages display, im sure its a mathematical equation in a while loop of some sort ?.... This is what I am using for my script: <?php //pagination test //pagination if (isset($_GET['Page'])) { $Page = mysql_real_escape_string($_GET['Page']); If($Page == '' OR !(is_numeric($Page))){ $Page = 1; } } else { $Page = 1; } $Check = mysql_query("SELECT ThreadStarter FROM forums WHERE Catergory='$Catergory'") Or die(mysql_error()); $rows_per_page = 15; $TotalRows = mysql_num_rows($Check); $LastPage = ceil($TotalRows/$rows_per_page); //numeric validation $Page = (int)$Page; if ($Page < 1) { $Page = 1; } elseif ($Page > $LastPage) { $Page = $LastPage; } $Limit = 'LIMIT ' .($Page - 1) * $rows_per_page .',' .$rows_per_page; if($Limit < 0) { $Limit = 0; } $Get = mysql_query("SELECT CreatedOn,ThreadID,ThreadStarter,ThreadName,LockedSticky,LastPost,LastUser FROM forums WHERE Catergory='$Catergory' ORDER BY LastPost DESC $Limit ") Or die(mysql_error()); //--------------------------------------------------------- If($TotalRows > 15){ if ($Page > 1) { $PrevPage = $Page-1;?> <li><a class=forums publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$PrevPage?>">Previous</a></li> <li><a class=forums href="publicforum.php?Catergory=<?=$Catergory?>&Page=1">First</a></li> <?php}ElseIf($Page == 1){ $NextPage = $Page+1;?> <li><a class=forums href="publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$NextPage?>">Next</a></li> <li><a class=forums href="publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$LastPage?>">Last</a></li> <?php} ElseIf ($Page == $LastPage) { $PrevPage = $Page-1; ?> <li><a href="publicforum.php?Catergory=<?=$Catergory?>&Page=1">First</a></li> <li><a href="publicforum.php?Catergory=<?=$Catergory?>&Page=<?=$PrevPage?>">Previous</a></li> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 18, 2008 Share Posted February 18, 2008 what you could do is devide the total ammount of rows by in your case 15, then use a for loop like this: for($i=0; $i <= $pages; $i++) { if($Page == $i) { echo "[ $i ]"; } else { echo "$i"; } } Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 18, 2008 Author Share Posted February 18, 2008 Yeh but then i get this: 0 1 2 3 I would rather some how get rid of the 0 so it starts on 1...if possible? =/ Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 18, 2008 Share Posted February 18, 2008 Yeah, just set $i to start at 1: for($i=1; $i <= $pages; $i++) { if($Page == $i) { echo "[ $i ]"; } else { echo "$i"; } } You might also want to ciel your result so you get the right amount of pages needed, Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 18, 2008 Author Share Posted February 18, 2008 Genius! Thanks Again! SOLVED 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.