Jump to content

"Last >>" and turning page 2-?&page=1 to ?&page=2


c-o-d-e

Recommended Posts

I have a pagination script, which displays 10 results a page, and shows the page lists as

<< First [1] [2] [3] so on.

I am not 100% sure it'll do << First [2] [3] [4] .. [15] (15 would be the last page)

I would like results, lets say theres 15 pages.. to display like this.

<< First [2] [3] [4] .. [14] Last >>

Also, if you click on << First, it'll be the first page, same for last. but with any [2] [3] so on- one of them pages.. to have a marker for that page. Lets say you clicked on [2], maybe the current page will turn red, or some sort of marker to let the user know what page there on.

 

www.developers-community.com/allnews.php

Use that link to see what I've got.

If you click on page [2] the URL is &page=1 I would like to change it to &page=2, but a simple method would remove the first set of results.

 

Can you help me on what to do?

    <?php
include 'config.php';
	$query = mysql_query("SELECT * FROM News ORDER BY Posted DESC") or trigger_error('Query failed: '. mysql_error());
        $totalrows = mysql_num_rows($query);

        $numberofpages = ceil($totalrows / '10');
                
        if(isset($_GET['page']))
	{

		$currentpage = $_GET['page'] * 10;
	}
		else
		{
			$currentpage = 0;
			};
$query2 = mysql_query("SELECT * FROM News ORDER BY Posted DESC LIMIT $currentpage, 10 ") or trigger_error('Query failed: '. mysql_error());

	$pages=0;
	$do='';

	while($pages < $numberofpages)

		{
		if($pages==0){$do .= '<a href="allnews.php"><< First</a> ';}else{
		$new = $pages++;
		$do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> ';};
	    $pages ++;
			}		
	while($row = mysql_fetch_array($query2))
	{
	echo '<h4 style="margin:0px; font-size:12px;">'. $row['Artname'] .'</h4>';
	echo '<h4 style="margin:0px; font-size:11px;">'. $row['Posted'] .'</h4>';		
        echo '<p style="margin:0px;">'. $row['Article'] .'</p><br />';
	}
echo $do;
?>

 

Thanks so much

Link to comment
https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/
Share on other sites

    <?php
include 'config.php';
	$query = mysql_query("SELECT * FROM News ORDER BY Posted DESC") or trigger_error('Query failed: '. mysql_error());
        $totalrows = mysql_num_rows($query);
        $numberofpages = ceil($totalrows / '10');
                        if(isset($_GET['page']))
	{
					$currentpage = $_GET['page'] * 10;
	}
		else
		{
			$currentpage = 0;
			};
$query2 = mysql_query("SELECT * FROM News ORDER BY Posted DESC LIMIT $currentpage, 10 ") or trigger_error('Query failed: '. mysql_error());
					$pages=0;
	$do='';
			while($pages < $numberofpages)
		{
		if($pages==0){$do .= '<a href="allnews.php"><< First</a> ';
}else if($pages==$numberofpages-1){
$do .= '<a href="allnews.php?page='.$new.'">Last>></a> ';
}
else{
		$new = $pages++;
if($_GET['page']==$pages){
$do .= '<a href="allnews.php?&page='.$new.'"><font color="red">['.$pages.']</font></a> ';
}else{
		$do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> ';
}
};
	    $pages ++;
			}
			while($row = mysql_fetch_array($query2))
	{
	echo '<h4 style="margin:0px; font-size:12px;">'. $row['Artname'] .'</h4>';
	echo '<h4 style="margin:0px; font-size:11px;">'. $row['Posted'] .'</h4>';
	        echo '<p style="margin:0px;">'. $row['Article'] .'</p><br />';
	}
echo $do;	
?>
//so, add the similar stuff to <<first, and Last>>, see the middle pages as reference

Sorry about the "bump"

I did more tests out with the code you gave me greatstar00

I have 27 "posts" which should display.. 10 each page, last page would display 7.

I believe it should look like..

<< First [2] Last >>

Instead it doesn't have the "Last >>"

 

Use the link at the beginning of the topic to preview it.

Whats the problem?

Ok, so I have something like this

	while($pages < $numberofpages){
		if($pages==0){$do .= '<a href="allnews.php"><< First</a> ';
		}
		else if($pages==$numberofpages-1){
				$do .= '<a href="allnews.php?&page='.$new.'">Last >></a> ';
			}else{
				$new = $pages+1;
			if($_GET['page']==$pages){
				$do .= '<a href="allnews.php?&page='.$new.'"><font color="red">['.$pages.']</font></a>';	
			} else {
				$do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> ';
				}
			}
				$pages ++;
			}	

 

It comes out like this

<< First [1] Last >>

First = Page 1

[1] = should be [2], but should display the 2nd page, but it displays page 3.

Last = displays page 3

 

Use the link, page [1] and Last are the same. When I have 27 results with a maximum of 10 a page.

$pages=1;
$do='';
while($pages <= $numberofpages){
		if($pages==0){
                                                  $do .= '<a href="allnews.php"><< First</a> ';
		}
		else if($pages==$numberofpages){
				$do .= '<a href="allnews.php?&page='.$new.'">Last >></a> ';
			}else{
				$new = $pages;	
		if($_GET['page']==$pages){
				$do .= '<a href="allnews.php?&page='.$new.'"><font color="red">['.$pages.']</font></a>';
				} else {
				$do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> ';					}
			}
				$pages ++;
			}	

Sorry for the little bump.  This is very complicated, if you can figure it out, let me know.

Otherwise, how will I edit the first code, to make it ..

[1] [2] [3] [4] [5] 

(5 being the last page, 1 being the first) but for example, for the current page, it'll be marked in red.

Thanks.

 

 

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.