1

hello guys im using this second part of pagination script to show pagination;

<?
if ($pageno == 1) {
   echo "<li class='previous-off'>«« İlk Sayfa</li> <li class='previous-off'>« Önceki Sayfa</li> ";
} else {
   echo " <li><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=1'>«« İlk Sayfa</a></li> ";
   $prevpage = $pageno-1;
   echo "<li> <a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$prevpage'>« Önceki Sayfa</a> </li>";
} // if
echo " <li class='active'>$pageno</li>";
if ($pageno == $lastpage) {
   echo " <li class='previous-off'>«« Sonraki</li> <li class='previous-off'>« Son Sayfa</li> ";
} else {
   $nextpage = $pageno+1;
   echo " <li class='next'><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$nextpage'>Sonraki »</a></li> ";
   echo " <li class='next'><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$lastpage'>Son Sayfa »»</a></li> ";
} // if
?>

like you see here: echo " <li class='active'>$pageno</li>"; i only can show first, prev, active page, next, last page..

my question is: i want to show more pages near active page.. how can i do this?

i mean pagination style is now like:

FIRST PREV 1 NEXT LAST

i want

FIRST PREV 1 2 3 4 5 6 7 NEXT LAST

thanks

3 Answers 3

2

Just add a loop which loops from the first to the last page numbers:

for($page_number = 1; $page_number <= $amount_of_pages; $page_number++)
    if($page_number == $pageno)
        echo " <li class='active'>$page_number (active)</li>";
    else
        echo " <li class='active'><a href="...">$page_number</a></li>";

To let this work you'd need to find the maximum amount of items and divide it with the amount of items on a page:

$result = mysql_query("SELECT COUNT(*) FROM table");
$row = mysql_fetch_row($result);
$amount_of_items = $row[0];
$amount_of_pages = $amount_of_items / 10; // 10 items on a page

Of course you need to add some checks and stuff, this only shows the basic principles.

Sign up to request clarification or add additional context in comments.

4 Comments

i do this: for($page_number = 1; $page_number <= $lastpage; $page_number++) echo " <li><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$page_number'>$page_number</a></li>"; this works. but it showing like FIRST PREV 1(active) 1 2 3 NEXT LAST
You can use some if statement to check if $page_number is equal to $pageno, in order to be able to show some indication/remove the link/etc. I have updated my answer to show an example.
well thank you i let it work! for($page_number = 1; $page_number <= $lastpage; $page_number++) echo "<li><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$page_number'>$page_number</a></li>"; this code is works but "active li style" is not working. all page numbers are showing standard <li>. how i can set <li class="active"> to current page and others normal?
kkkkk my mistake sorry lol. it works very very fine! thank you so much veger.. now im gonna sent last version of script. thank you
0

Between the part which displays the previous page links and the part which displays the next page links, you need a loop between 1 and total pages.

<?php
$currentPage = 3;
$totalPages = 10;
?>

<a href="">First page</a>
<a href="">Prev page</a>

<?php
for ($i = 0; < $totalPages; $i++) {
    printf('<a href="%s?page=%d" class="%s">Page %d</a>', $_SERVER['PHP_SELF'], $i, ($i == $currentPage ? 'active' : ''), $i);
}
?>

<a href="">Next page</a>
<a href="">Last page</a>

Comments

0
<?
if ($pageno == 1) {
   echo "<li class='previous-off'>«« İlk Sayfa</li> <li class='previous-off'>« Önceki Sayfa</li> ";
} else {
   echo " <li><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=1'>«« İlk Sayfa</a></li> ";
   $prevpage = $pageno-1;
   echo "<li> <a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$prevpage'>« Önceki Sayfa</a> </li>";
} // if
for($page_number = 1; $page_number <= $lastpage; $page_number++)
if($page_number == $pageno) {
echo "<li class='active'>$pageno</li>";
}
else {
echo "<li><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$page_number'>$page_number</a></li>";
}

if ($pageno == $lastpage) {
   echo " <li class='previous-off'>«« Sonraki</li> <li class='previous-off'>« Son Sayfa</li> ";
} else {
   $nextpage = $pageno+1;
   echo " <li class='next'><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$nextpage'>Sonraki »</a></li> ";
   echo " <li class='next'><a href='{$_SERVER['PHP_SELF']}?isim=$kid&sayfa=$lastpage'>Son Sayfa »»</a></li> ";
} // if
?>

this is fixed version. works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.