[Solved] Problem on Displaying Page Numbers...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Drayton
Forum Newbie
Posts: 24
Joined: Thu Apr 01, 2004 2:14 am

[Solved] Problem on Displaying Page Numbers...

Post by Drayton »

Hi to all Concerned Programmers!

hirs my code:
Admin Edit: Removed bold tags and added tags to code.[/size][/color]

Code: Select all

$numPage	=	$num_record / 30;
						print"<td width="800">PAGE : ";
						for($page = 0 ; $page <= $numPage ; $page ++){
						$tempbegin1= $page * 30;
						$pageNum = $page + 1;
						print"<a href="$PHP_SELF?tempbegin=$tempbegin1" class="page">$pageNum &nbsp;</a>";
						
						}
What happen to my code is that it displays all the page number. I want to display only the the first three page numbers and the last three page numbers.

Thanks!
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post by Pozor »

hello,

here the solution you searched for:

Code: Select all

<?php
$num_record = 3000; 
$numPage   =   $num_record / 30;
$dots = 0; 
for($page = 0 ; $page < $numPage ; $page ++)
{ 
  $tempbegin1= $page * 30; 
  $pageNum = $page + 1; 
  if(($page < 3) or ($page > $numPage - 4))
  {
    echo '<a href="blabla" class="page">'.$pageNum.'</a>&nbsp;'; 
  }elseif(0 == $dots)
  {
    echo ' ... ';
    $dots = 1;
  }
}
?>

soory that i didn't code this in your style, but i like this more (i my opinion it's better readable :wink: )

but it work anyway...


greez Pozor
User avatar
Drayton
Forum Newbie
Posts: 24
Joined: Thu Apr 01, 2004 2:14 am

Post by Drayton »

Hey Bro,

Your code works just great, thanks for the help! I really appreciate it. Hope to see you around again, if I have other questions!
Post Reply