Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-23-2003, 03:10 AM   PM User | #1
celestine
Regular Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
celestine is an unknown quantity at this point
Advance Dynamic Paging

Greetings all,

I have been using a simple dynamic paging script to print out the pages for my application. it works fine until I have over 15 pages to scroll and cannot fit them nicely in a line. I saw on certain websites, they have page navigation like:

prev < 2 ... 10 > next

I was wondering how I can amend my code to do that?

The code I have is as follows:-

PHP Code:

$result 
mysql_query($sql);
$rows_per_page=15;
$total_records=mysql_num_rows($result);
$pages ceil($total_records $rows_per_page);
            
echo 
"<p>$total_records records in database.</p>";
if (!isset(
$screen))
$screen=0;
$start $screen $rows_per_page;
$sql .= "LIMIT $start, $rows_per_page";
$result mysql_query($sql);

while(
$myrow=mysql_fetch_array($result))
{
extract($myrow);
// print out data here.
}
// create the dynamic links
    
if ($screen 0)    {
        
$j $screen 1;
        
$url "$PHP_SELF?action=list&type=$design_id&screen=$j";
        echo 
"<a href=\"$url\">Prev</a>";
    }

    
// page numbering links now

    
for ($i 0$i $pages$i++)    {
        
$url "$PHP_SELF?action=list&type=$design_id&screen=" $i;
        
$j $i 1;
        echo 
" | <a href=\"$url\">$j</a> | ";
    }

    if (
$screen $pages-1)    {
        
$j $screen 1;
        
$url "$PHP_SELF?action=list&type=$design_id&screen=$j";
        echo 
"<a href=\"$url\">Next</a>";
    } 
The above code display my pages like:-
1 | 2 | 3 | 4 | next etc,
celestine is offline   Reply With Quote
Old 12-23-2003, 04:10 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
Change :
PHP Code:
for_($i 0;_$i_<_$pages;_$i++)____{

________$url_=_"$PHP_SELF?action=list&type=$design_id&screen="_._$i;

________$j_=_$i_+_1;

________echo_"_| <a_href=\"$url\">$j</a> |_";

____
into
PHP Code:
for_($i_=_0;_$i_<=_10;_$i++)____{

________$url_=_"$PHP_SELF?action=list&type=$design_id&screen="_._$i;

________$j_=_$i_+_1

________echo_"_| <a_href=\"$url\">$j</a> |_";

____}
If (
$pages 10) {
        
$url_=_"$PHP_SELF?action=list&type=$design_id&screen=11";

________echo_"_| <a_href=\"$url\">$j</a> |_";
echo

well, it'll need some extra's bcause i can imagen you would like to get the next 10 links (previous - 11-20 - next) so you'll have a few extra conditions like
PHP Code:
if ($screen 10) {
    echo 
previous .....

and you then can't set the screen to $i but you need to have another incrementing variable inside the for-loop like
PHP Code:
$lowest 10;
for_($i_=_0;_$i_<=_10;_$i++)____{

_______ $url_=_"$PHP_SELF?action=list&type=$design_id&screen="_._$lowest;

________$lowest ++; 
        
$j_=_$i_+_1;
________echo_"_| <a_href=\"$url\">$j</a> |_";

____
end so on

<edit>ignore the underscores, i don't know how they get added)</edit>
raf is offline   Reply With Quote
Old 12-26-2003, 08:46 AM   PM User | #3
celestine
Regular Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
celestine is an unknown quantity at this point
Cool

thank you. raf.. I'll give it a shot later.
celestine is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:45 PM.


Advertisement
Log in to turn off these ads.