This should do it. i didnt have time to test so there may be some bugs.

function pageit($limit , $total, $page, $link)
{
        $last = intval($total / $limit) + ($total % $limit ==0 ? 0:1);
        if(!is_numeric($page) || $page > $last)
                $page = 1;

        $pages[] = 1;

        if($page == 1)
        {
                $pages[] = 2;
                $pages[] = 3;
        }
        else
        if($page == $last)
        {
                $pages[]= $last - 2;
                $pages[] = $last -1;
        }
        else
        {
                if($page - 1 > 1)
                        $pages[] = $page -1;
                $pages[] = $page;
                if($page +1 < $last)
                        $pages[] = $page +1;

        }

        $pages[] = $last;

        for($i=0; $i < count($pages) ; $i++)
        {
                if($pages[$i] <1 || $pages[$i] > $last)
                        continue;
                if($i>0)
                        if($pages[$i] - $pages[$i-1] > 1 )
                                echo '...';
                echo '<a href="' . $link . '?page=' . $pages[$i]. '">' . 
$pages[$i] . '</a>';
        }
}




-----Original Message-----
From: Angelo Zanetti [mailto:ang...@elemental.co.za]
Sent: Wednesday, September 30, 2009 1:59 PM
To: Mert Oztekin; php-general@lists.php.net
Subject: RE: [PHP] Paging script



-----Original Message-----
From: Mert Oztekin [mailto:mozte...@anadolusigorta.com.tr]
Sent: 30 September 2009 12:40 PM
To: 'Angelo Zanetti'; php-general@lists.php.net
Subject: RE: [PHP] Paging script

Sorry but I dont understand what you mean. Can you be more specific?

{1} 2 3 ... 12  (Startup / Total 12 pages)
When you click 7
1 ... 6 {7} 8 ... 12
When you click 11 or 12
1 ... 10 11 {12}

Do you mean something like this?


Hi Mert,

Yes I mean exactly like you have it there,

Regards
Angelo



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Bu mesaj ve ekleri, mesajda g?nderildi?i belirtilen ki?i/ki?ilere ?zeldir ve 
gizlidir. Size yanl??l?kla ula?m??sa l?tfen g?nderen kisiyi bilgilendiriniz ve 
mesaj? sisteminizden siliniz. Mesaj ve eklerinin i?eri?i ile ilgili olarak 
?irketimizin herhangi bir hukuki sorumlulu?u bulunmamaktad?r. ?irketimiz 
mesaj?n ve bilgilerinin size de?i?ikli?e u?rayarak veya ge? ula?mas?ndan, 
b?t?nl???n?n ve gizlili?inin korunamamas?ndan, vir?s i?ermesinden ve bilgisayar 
sisteminize verebilece?i herhangi bir zarardan sorumlu tutulamaz.

This message and attachments are confidential and intended for the 
individual(s) stated in this message. If you received this message in error, 
please immediately notify the sender and delete it from your system. Our 
company has no legal responsibility for the contents of the message and its 
attachments. Our company shall have no liability for any changes or late 
receiving, loss of integrity and confidentiality, viruses and any damages 
caused in anyway to your computer system.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to