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 07-09-2007, 03:15 AM   PM User | #1
nurvirus
New Coder

 
Join Date: Jul 2007
Location: malaysia
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
nurvirus is an unknown quantity at this point
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';
?>
nurvirus is offline   Reply With Quote
Old 07-09-2007, 04:49 AM   PM User | #2
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
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
PappaJohn is offline   Reply With Quote
Old 07-09-2007, 04:57 AM   PM User | #3
nurvirus
New Coder

 
Join Date: Jul 2007
Location: malaysia
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
nurvirus is an unknown quantity at this point
it works! thank you so much for your help
nurvirus 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 07:52 AM.


Advertisement
Log in to turn off these ads.