Jump to content

Pagination help (Again)


EchoFool

Recommended Posts

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			} }
			?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/91720-pagination-help-again/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/91720-pagination-help-again/#findComment-469786
Share on other sites

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,

Link to comment
https://forums.phpfreaks.com/topic/91720-pagination-help-again/#findComment-469805
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.