Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2007
    Location
    malaysia
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with paging



    Can someone please help me.. I'm doing paging for my website. As you can see in the picture it is done. But, my problem is.. the No. column i didnt take it from database, i'm using loop. So when i click on next, the number restarting at 1 2 3 instead of continuing 6,7,8. Hope someone can help me. Thank you.

    PHP Code:
    <?php

    //connection
    include 'library/config.php';
    include 
    'library/opendb.php';

    // how many rows to show per page
    $rowsPerPage 5;

    // by default we show first page
    $pageNum 1;

    // if $_GET['page'] defined, use it as page number
    if(isset($_GET['page']))
    {
        
    $pageNum $_GET['page'];
    }

    // counting the offset
    $offset = ($pageNum 1) * $rowsPerPage;

    $query  "SELECT memo_code, memo_date, memo_title, memo_sender
               FROM memo where id='$memo_code' "
    ;
               
    $pagingQuery "LIMIT $offset, $rowsPerPage";
    $result mysql_query($query $pagingQuery) or die('Error, query failed');



     
    //numbering
     
    $counter=($pageNum 1) * $rowsPerPage;
     
     
    $number"LIMIT $counter, $rowsPerPage";
        
    $number=1;



    // print the memo info in table
    echo '<table border="1" width="100%"><tr bordercolor="0" bgcolor="#CCCCCC"><td width="1%" bordercolor="#FFFFFF"><div align="center">NO.</td><td width="3%" bordercolor="#FFFFFF"><div align="center">DATE</td><td width="22%" bordercolor="#FFFFFF"><div align="center">TITLE</td></tr>';
    while(list(
    $memo_code$memo_date$memo_title) = mysql_fetch_array($result))
    {
        echo 
    "<tr>";
        
    ?>

        <td bordercolor='#FFFFFF' bgcolor='#FFFFCC'><div align="center"><? echo $number ?></td>

        <td bordercolor='#FFFFFF' bgcolor='#CCCCCC'><div align="center"><? echo $memo_date ?></td>

        <td bordercolor='#FFFFFF' bgcolor='#FFFFCC'><a href="memo_content.php?id=<?php echo $memo_code?>"><?echo $memo_title;?></td>
        <?


           $number 
    ++;




        echo 
    "</tr>";
    }
        echo 
    '</table>';
        echo 
    '<br>';

    // how many rows we have in database
    $result  mysql_query($query) or die('Error, query failed');
    $numrows mysql_num_rows($result);

    // how many pages we have when using paging?
    $maxPage ceil($numrows/$rowsPerPage);

    $self $_SERVER['PHP_SELF'];

    // creating 'previous' and 'next' link
    // plus 'first page' and 'last page' link




    // print 'previous' link only if we're not
    // on page one
    if ($pageNum 1)
    {
        
    $page $pageNum 1;
        
    $prev " <a href=\"$self?page=$page\">[Prev]</a> ";

        
    $first " <a href=\"$self?page=1\">[First Page]</a> ";
    }
    else
    {
        
    $prev  '  ';  // we're on page one, don't enable 'previous' link
        
    $first '  '// nor 'first page' link
    }

    // print 'next' link only if we're not
    // on the last page
    if ($pageNum $maxPage)
    {
        
    $page $pageNum 1;

        
    $next " <a href=\"$self?page=$page\">[Next]</a> ";

        
    $last " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
    }
    else
    {
        
    $next '  ';  // we're on the last page, don't enable 'next' link
        
    $last '  '// nor 'last page' link
    }

    // print the page navigation link
    echo $first $prev " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " $next $last;

    include 
    'library/closedb.php';
    ?>

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    I'm not sure what you're trying to accomplish here
    PHP Code:
    $number"LIMIT $counter, $rowsPerPage";
        
    $number=1
    since you set $number to a string and then immediately set it to 1.

    But anyway, since you are using $number as your row counter, try replacing
    PHP Code:
        $number=1
    with
    PHP Code:
    $number = (($pageNum 1) * $rowsPerPage) + 1

  • #3
    New Coder
    Join Date
    Jul 2007
    Location
    malaysia
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it works! thank you so much for your help


  •  

    Posting Permissions

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