google style pagination

mmm… anyone know how to implement the Google style pagination?
Can give me a simple example to study? 8)

[php]$result = mysql_query(“SELECT COUNT(*) FROM asset WHERE Asset_Class LIKE '%”.$search."%’ OR Location LIKE ‘%".$search."%’ OR Serial_number LIKE ‘%".$search."%’ OR PIC LIKE '%".$search."%'LIMIT $start_from ,25");

//echo $search;

$row = mysql_fetch_row($result);
//$adjacents = 3;
$total_records = $row[0];

$total_pages = ceil($total_records/20);	//next page is page + 1
//$lastpage = ceil($total_records/25);		//lastpage is = total pages / items per page, rounded up.
	//echo $total_pages;
	//echo $page;
	
	
	
	echo"<center>";
	// Build Previous Link 
	
	if($page > 1){ 
	$prev = ($page - 1); 
	echo "<a href=search.php?page=$prev&search=$_GET[search]>Previous</a>&nbsp "; 
	
	for($i = 1; $i <= $page; $i++){ 
	if(($page) == $i){ 
//	echo "$i&nbsp;"; 
	} else { 
	echo "<a href=search.php?page=$i&search=$_GET[search]>[$i]</a>&nbsp  "; 
	} 
	} 
	
	$next = ($page + 1); 
	echo "<a href=search.php?page=$next&search=$_GET[search]>Next</a>  "; 
	
	
	//echo $total_pages;
	
	} 
	
	for($i = 1; $i <= $total_pages; $i++){ 
	if(($page) == $i){ 
	echo "[$i]&nbsp;"; 
	} else { 
	echo "<a href=search.php?page=$i&search=$_GET[search]>[$i]</a>&nbsp  "; 
	} 
	} 

	
	
	// Build Next Link 
	if($page < $total_pages){ 
	$next = ($page + 1); 
	echo "<a href=search.php?page=$next&search=$_GET[search]>Next</a>  "; 
	} 
	echo "</center>"; 
	} [/php]

I wants the pagination is look like
Previous 1 2 3 4 5 NEXT
but i only can show Previous 1 2 3 4 5 NEXT…
if I click page 3 then it will only show Previous 1 2 NEXT
However i don’t want like this I want is like first one look like Previous 1 2 3 4 5 NEXT
So Please help me!!
What is the problem of my coding…

Well, basically, pagination like “PREV 1 2 3 4 5 NEXT” would be just LINKS to your posting pages.
You would set a limit, such as 20 items per page. The current item would be #3. The user can click on any of the others “PREV” “1” “2” “4” “5” “next”… These are JUST links. HREF’s…

You create your display page to use an argument. Your “www.mysite.com/display.php” becomes something like “www.mysite.com/display.php?page=3”… You read the page number with a $_GET[‘page’]. And, the displayed page starts at (page - 1) * 20. So, page 1 displays 0 to 19 items. Page 2 displays 20 to 39 items… Etc…

For the “PREV 1 2 3 4 5 NEXT”, you would calculate the 6 items other than the current page (which is always #3) and create a link that points to the display page with argument that points at the page number. Something like: 4 This was an example where page 22 falls on the screen as the next page to display.
*** Note: PREV always is 1 less for page#, NEXT is always page# +1, and both of these would be the same as #2 and #4 since using PREV would go to the #2 position, using NEXT would go to the #4 position. Sounds a bit complicated, but, put it on paper for a moment and it will make sense.

If you can’t understand it, ask away… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service