Current location: Hot Scripts Forums » Programming Languages » PHP » Pagination Help


Pagination Help

Reply
  #1 (permalink)  
Old 01-06-08, 08:43 AM
Nikas Nikas is offline
Coding Addict
 
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
Pagination Help

Hi,

How can I improve this pagination to become better. In a way that, currently, what is shows is << Prev 1 2 3 4 5 Next >> .

If there is 6, 7, 8, 9 pages, it will continue and made the list very long. How can I make it looks like this forum pagination? Or something like that.

<< Prev 1 2 3 4 5 50 100 > Last >>

My current pagination is like this

PHP Code:

<?php

$QQQ 
mysql_query("SELECT * FROM mtoggle_incoming WHERE incoming_content LIKE 'DOTCOM %'");
                                        
                                        
                                        if (!
$QQQ) die(mysql_error());  
                                        
// Get the total number of rows
                                        
$total_items mysql_num_rows($QQQ);
                                        
                                        
// Get the page limit & page
                                        
$limit        $_GET['limit'];
                                        
$page        $_GET['page'];
                                        
                                        
// Do default setting
                                        
if((!$limit)  || (is_numeric($limit) == false) || ($limit 10) || ($limit 50)) {
                                        
$limit 5//default
                                        

                                        
                                        
// Do default setting
                                        
if((!$page) || (is_numeric($page) == false) || ($page 0) || ($page $total_items)) {
                                          
$page 1//default
                                        

                                        
                                        
// Calculate the number to page to display
                                        
$total_pages     ceil($total_items $limit);
                                        
$set_limit     $page $limit - ($limit);

                                        
$QQQ1 mysql_query("SELECT * FROM mtoggle_incoming WHERE incoming_content LIKE 'DOTCOM %' LIMIT $set_limit$limit");
                                        if(!
$QQQ1) die(mysql_error());
                                        
$err mysql_num_rows($QQQ1);
                                            if(
$err == 0) die("No matches met your criteria.");
                                        
                                        
// Let user decide how many result to show in each page
                                        
echo "Results per page:  ";
                                        echo 
"<a href='usermsghistory.php?limit=10&page=1'>10</a> | 
                                        <a href='usermsghistory.php?limit=25&page=1'>25</a> | 
                                        <a href='usermsghistory.php?limit=50&page=1'>50</a>"
;
                                        
                                        
//Count Message
                                        
$count 1;
                                        
                                        
//to loop the results into the table rows
                                        
while($FFF mysql_fetch_assoc($QQQ1)) {
                                        
?>
                                      <tr>
                                        <td width="14">&nbsp;</td>
                                          <td width="52" class="overview">
                                            <? 
                                                
echo $count;
                                                
$count++;
                                            
?>                                        
                                        </td>
                                        <td width="10" class="overview">
                                        <?php if (substr($FFF['sender'], 01) == "+") { 
                                        echo 
"<img src='images/hp.png'>"; } 
                                        else { 
                                            if (
$FFF['readd'] == 1) {
                                        echo 
"<img src='images/email_read.gif'>"; } 
                                            else {
                                                echo 
"<img src='images/email_unread.gif'>"; }
                                        }
                                        
?>
                                        </td>
                                        <td width="110" class="overview"><?php echo $FFF['sender']; ?></td>
                                        <td width="141" class="overview"><?php echo $FFF['subject']; ?></td>
                                        <td width="88" class="overview"><?php echo $FFF['timee']; ?></td>
                                        <td width="99" class="overview">
                                          <div id="submenualt">
                                            <ul>
                                                <li><a href="usermsghistory_delete.php?pid=<?php echo $FFF['id']; ?>">Delete</a></li>
                                                <li><a href="usermsghistory_read.php?pid=<?php echo $FFF['id']; ?>">Read</a></li>
                                            </ul>
                                        </div>                                    </td>
                                        <td width="20">&nbsp;</td>
                                      </tr>
                                      <tr>
                                        <td width="14" class="overviewline"><img name="" src="" width="1" height="1" alt="" /></td>
                                        <td height="1" colspan="5" bgcolor="#EBF3F5" class="overviewline"><img name="" src="" width="1" height="1" alt="" /></td>
                                        <td width="20" class="overviewline"><img name="" src="" width="1" height="1" alt="" /></td>
                                      </tr> 
                                       <?php
                                        

                                        
?>
                                      <tr>
                                        <td width="14">&nbsp;</td>
                                        <td width="52">&nbsp;</td>
                                        <td width="110">&nbsp;</td>
                                        <td width="141">&nbsp;</td>
                                        <td width="88">&nbsp;</td>
                                        <td width="99">&nbsp;</td>
                                        <td width="20">
                                        <?php 
                                        
                                        $prev_page 
$page 1;
            
                                        if(
$prev_page >= 1) { 
                                          echo(
"<b><<</b> <a href=usermsghistory.php?limit=$limit&page=$prev_page><b>Prev.</b></a>"); 
                                        } 
                                        
                                        for(
$i 1$i <= $total_pages$i++){
                                            if(
$i == $page){
                                                echo(
$i." ");
                                            }else{
                                                echo(
"<a href=\"usermsghistory.php?limit=$limit&page=$i\">$i</a> ");
                                            }
                                        } 
            
                                        
$next_page $page 1;
                                        if(
$next_page <= $total_pages) {
                                           echo(
"<a href=usermsghistory.php?limit=$limit&page=$next_page><b>Next</b></a> > >"); 
                                        } 
            
                                        
//dbDisconnect($conn2);
                                        
?></td> ?>
Reply With Quote
  #2 (permalink)  
Old 01-06-08, 11:42 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Try searching Google for 'php advanced pagination'. There are about 28,000 articles and quite a few of them have code that shows what you want. This is a subject that has been discussed repeatedly here, so you could also search this forum for example code.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 03-10-08, 05:38 PM
techker techker is offline
Newbie Coder
 
Join Date: May 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
finally i find a working script..lol THX!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Pagination? End User Script Requests 1 11-10-06 01:38 PM
pagination pumpernickles pilch PHP 0 05-17-06 11:24 AM
Pagination Problem lppa2004 PHP 1 03-24-06 07:54 PM
Small Job, Easy Money. Pagination Script... themodestguy Job Offers & Assistance 3 08-28-05 07:26 PM
Pagination MrDarko PHP 1 09-28-04 08:10 AM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.