Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Displaying amount of pages correctly
Old 08-26-2004, 09:07 PM Displaying amount of pages correctly
Unknown.

Posts: 1,693
Trades: 0
Im using a script to fetch results from mysql and then display a certain number per page...

This part is used to display the numbers of pages.. also linking to the pages...

PHP Code:
for($i 1$i <= $total_pages$i++){ 
    if((
$page) == $i){ 
        echo 
"$i&nbsp;"
        } else { 
            echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>&nbsp;"
    } 

So it displays 1 2 3 4 5 6 7 etc depending on the number of pages...

Theres also the <<Previous and Next >> links but thats a different part of the script..

The problem is when I have 170 pages of results it displays..

1 2 3 4 4 5 6 7...... all the way upto 170 which expands the screen width and makes it look a mess...

What I want it to look like is like on this forum when you view multiple pages...

So it only displays a few numbers like...

<< 55 56 57 58 59 >>

How would I do this??

Thanks

--James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-27-2004, 04:53 AM
Ultra Talker

Posts: 377
Trades: 0
Code:
for($i = $from; $i <= $from+5; $i++)
{
        if(($page) == $i)
        { 
                                echo "$i&nbsp;"; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>&nbsp;"; 
        } 
}
all you need to do is to send a right $from variable to your script. and there should be the links like
<a href="yourscript.php?from=<?$from+6?>"> &nbsp>>&nbsp </a>
<a href="yourscript.php?from=<?$from-6?>"> &nbsp<<&nbsp </a>
i think it shoud work...
__________________
andrews_john

Please login or register to view this content. Registration is FREE
andrews_john is offline
Reply With Quote
View Public Profile Visit andrews_john's homepage!
 
Old 08-27-2004, 06:40 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
PHP Code:
for($i = (($page-2)<1?1:($page-2)); $i <= (($page+2)>$total_pages?$total_pages:($page+2)); $i++){ 
    if((
$page) == $i){ 
        echo 
"$i&nbsp;"
        } else { 
            echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>&nbsp;"
    } 

I haven't bothered checking that for bugs btw.
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-27-2004, 05:27 PM
Unknown.

Posts: 1,693
Trades: 0
Thanks works fine

--James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Displaying amount of pages correctly
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13382 seconds with 12 queries