SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict kuldeepkaundal's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Paging Modification

    hi,

    I've put in simple paging in one of my applications to display no of records. it works fine in the following way:

    1 2 3 4 5 6 7 8 9 10 NEXT

    But, now my requirement is to display paging like:

    1 2 3 4 5 NEXT on page1 And
    PREV 2 3 4 5 6 NEXT on page2 and so on.. I mean numbering upto 5 pages only on each page, at the moment i've used following code:
    PHP Code:
    <?php
      $query_record2 
    "SELECT DISTINCT message_id FROM `tbl_mail_record` WHERE message_to = ".$logged_user_id." ORDER BY message_date DESC";
                    
    $result_record2 mysql_query($query_record2);
                     
    $nume=mysql_num_rows($result_record2); 
                      
    // Code for paging------count the total no of records..
           
    $start=$_GET['start'];// To take care global variable if OFF
           
    if(!($start 0)) { // This variable is set to zero for the first page
          
    $start 0;
            }
            
    $eu = ($start 0);
    $limit 12// No of records to be shown per page.
    $current $eu $limit;
    $back $eu $limit;
    $next $eu $limit
            
    $query_record "SELECT DISTINCT message_id FROM `tbl_mail_record` WHERE message_to = ".$logged_user_id." ORDER BY message_date DESC limit $eu$limit";
                    
    $result_record mysql_query($query_record); 
    ?>

    [B]
    And for displaying page nos, m using following code:[/B]

    <?php 

    echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
    if(
    $back >=0) {
    print 
    "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
    }
      echo 
    "</td><td align=center width='30%'>";
    $i=0;
    $l=1;
    for(
    $i=0;$i $nume;$i=$i+$limit){
    if(
    $i <> $eu){
    echo 
    " <a href='$page_name?type=inbox&start=$i'><font face='Verdana' size='2'>$l</font></a> ";
    }
    else { echo 
    "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
    $l=$l+1;
    }
        echo 
    "</td><td align='right' width='30%'>";
    if(
    $current $nume) {
    print 
    "<a href='$page_name?type=inbox&start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
    echo 
    "</td></tr></table>";  

     
    ?>
    I've tried on this, but not finding the way, though m still working at it.

    Can someone suggest a way of achieving this?

    Thanks,
    kul.
    Last edited by kuldeepkaundal; Dec 30, 2008 at 04:25.

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please use [php] or [code] tags as suggested in the post called read before you post.

    Code is hard to read when you don't, and you want to make it as easy as possible for others to help you.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Addict kuldeepkaundal's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've already put in <?php ?> tags in my code, and also have put in the code used for paging only.

    Please have a look at it.

    Thanks,
    kul.

  4. #4
    SitePoint Addict kuldeepkaundal's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way of achiving this?

    Plz suggest,
    Thanks in advance,
    kul.

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As bhanson wrote, put your code inside [php] tags, not <?php ?>, if you edit your post there is an icon, just before "Syntax" with a small page with 'php' written on it, use it.
    You could do it by adding [ PHP ] your code [ /PHP ] by hand, so your code will look like this:

    PHP Code:
        if ($that)
        {
            echo 
    "Hello"
        


  6. #6
    SitePoint Addict kuldeepkaundal's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    k, got it, plz check the code now!

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Quote Originally Posted by kuldeepkaundal View Post
    hi,

    I've put in simple paging in one of my applications to display no of records. it works fine in the following way:

    1 2 3 4 5 6 7 8 9 10 NEXT

    But, now my requirement is to display paging like:

    1 2 3 4 5 NEXT on page1 And
    PREV 2 3 4 5 6 NEXT on page2 and so on.. I mean numbering upto 5 pages only on each page, at the moment i've used following code:

    PHP Code:
      $query_record2 "SELECT DISTINCT message_id FROM `tbl_mail_record` WHERE message_to = ".$logged_user_id." ORDER BY message_date DESC";
                    
    $result_record2 mysql_query($query_record2);
                     
    $nume=mysql_num_rows($result_record2); 
                      
    // Code for paging------count the total no of records..
           
    $start=$_GET['start'];// To take care global variable if OFF
           
    if(!($start 0)) { // This variable is set to zero for the first page
          
    $start 0;
            }
            
    $eu = ($start 0);
    $limit 12// No of records to be shown per page.
    $current $eu $limit;
    $back $eu $limit;
    $next $eu $limit
            
    $query_record "SELECT DISTINCT message_id FROM `tbl_mail_record` WHERE message_to = ".$logged_user_id." ORDER BY message_date DESC limit $eu$limit";
                    
    $result_record mysql_query($query_record); 

    And for displaying page nos, m using following code:


    PHP Code:
    echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
    if(
    $back >=0) {
    print 
    "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
    }
      echo 
    "</td><td align=center width='30%'>";
    $i=0;
    $l=1;
    for(
    $i=0;$i $nume;$i=$i+$limit){
    if(
    $i <> $eu){
    echo 
    " <a href='$page_name?type=inbox&start=$i'><font face='Verdana' size='2'>$l</font></a> ";
    }
    else { echo 
    "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
    $l=$l+1;
    }
        echo 
    "</td><td align='right' width='30%'>";
    if(
    $current $nume) {
    print 
    "<a href='$page_name?type=inbox&start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
    echo 
    "</td></tr></table>"
    I would start with replacing "for($i=0;$i < $nume;$i=$i+$limit)" with a code that iterates over $currentPageNum-$pagesAround to $currentPageNum-1 (in your $currentPageNum=$eu), then display the $currentPageNum and after that iterate over $currentPageNum+1 to currentPageNum+$pagesAround.
    Where $pagesAround in your case would be 2.

    Of course you should add the contrainst that $i should be > 0 and < $nume.
    Last edited by krzyk; Dec 30, 2008 at 04:31. Reason: clarification


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •