Issue with pagination columns and rows in PHP - php

I'd like to display 20 records in 5 columns with 4 rows and have the "Next"/"Previous" button at the bottom.
For some reason, $rowsperpage = 5 winds up in 1 row and 5 columns. If I increase the number, it just adds another column.
The actual pagination works fine but the columns and rows aren't cooperating.
Any idea how I can achieve the desired effect?
Here's the code I'm using:
<?php
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM users";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 5;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT id, name, picture, phone, address1 FROM users LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
echo "<table style='width: 800px; height: 250px'>";
echo "<tr style='width: 800px;'>";
while ($list = mysql_fetch_assoc($result)) {
// echo data
echo "<td align='center' style='width: 800px; height: 250px'>" . $list ['name'] . "<br /><a href='http://www.snarrf.com/onsale/detail.php?id=" . $list ['id'] . "'><img src='http://www.snarrf.com/onsale/nooks/" . $list['picture'] . "' height='100' width='100' border='0' /></a><br />" . $list['address1'] ."</td>" ;
} // end while
echo "</tr>";
echo "</table>";
/****** build the pagination links ******/
echo "<table align='center' >";
echo "<tr >";
echo "<td align='center' valign='top'><img src='images/sn1.gif'><br></td>";
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo "<td align='center'> <img src='images/sn2.gif' border='0'><br>$x </td>";
// if not current page...
} else {
// make it a link
echo " <td align='center' valign='top'><a href='{$_SERVER['PHP_SELF']}? currentpage=$x'><img src='images/sn2.gif' border='0'><br>$x</a> </td>";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
echo "<td valign='top'><img src='images/sn3.gif'><br></td>";
echo "</tr>";
echo "</table>";
echo "<table align='center' width='100' >";
echo "<tr width='100' >";
echo "<td >";
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
// if not current page...
} else {
// make it a link
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
echo "</td>";
echo "</tr>";
echo "</table>";
/****** end build pagination links ******/
?>

I believe replacing
while ($list = mysql_fetch_assoc($result)) {
echo "<td align='center' style='width: 800px; height: 250px'>" . $list ['name'] . "<br /><a href='http://www.snarrf.com/onsale/detail.php?id=" . $list ['id'] . "'><img src='http://www.snarrf.com/onsale/nooks/" . $list['picture'] . "' height='100' width='100' border='0' /></a><br />" . $list['address1'] ."</td>" ;
}
with
$rows_counter = 0;
while ($list = mysql_fetch_assoc($result)) {
echo "<td align='center' style='height: 250px'>" . $list['name'] . "<br /><a href='http://www.snarrf.com/onsale/detail.php?id=" . $list['id'] . "'><img src='http://www.snarrf.com/onsale/nooks/" . $list['picture'] . "' height='100' width='100' border='0' /></a><br />" . $list['address1'] ."</td>" ;
if (!(++$rows_counter % 5) and $rowsperpage != $rows_counter)
echo "</tr><tr>";
}
Should do what you are looking for.

Related

Pagination links not displaying all pages

I am trying to read data from the WordPress database table and display it on my website. This is my pagination script and I am able to get all the data. The limit and number of rows per page are all fine. When I change pages, I still see the first page but the url changes. Please how do I handle this? Thank you
<?php
global $wpdb;
$er = $wpdb->show_errors();
$result = $wpdb->get_results("SELECT * FROM koh_user");
// number of rows to show per page
$rowsperpage = 10;
// find out how many rows are in the table
$numrows = $wpdb->num_rows;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
// cast var as int
$page = (int) $_GET['page'];
} else {
// default page num
$page = 1;
}
// the offset of the list, based on current page
$offset = ($page - 1) * $rowsperpage;
// get the info from the db
$result = $wpdb->get_results("SELECT CONCAT( koh_user.fname, ' ', koh_user.lname) as name, koh_user.id as id, koh_user.username as username from koh_user LIMIT $rowsperpage OFFSET $offset
");
// Display the rows
echo "<style>";
echo "body {font-family: Arial;}";
echo ".table_container { padding: 10px 12px 0px 12px; border: 1px solid #ccc; }";
echo ".table_container th { background-color:lightblue; color:black; font-weight:bold; border-left: 1px solid white;}";
echo "</style></head>";
echo "<body>";
echo "<div class=\"table_container\"><table>";
echo "<tr><th style=\"padding-left:10px;\">Nom</th><th>Nom d'utilisateur</th><th>Role</th><th></th></tr>";
foreach ($result as $row) {
echo "<tr class ='info'>
<td>" . $row->name . "</td>
<td>" . $row->username . "</td>
<td>" . $row->role . "</td>
<td>
</td>
</tr>"
;}
echo "</table></div>";
// loop to show links to range of pages around current page
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($page > 1) {
// show << link to go back to page 1
echo " <a href='/?page_id=347?page=1'><<</a> ";
// get previous page num
$prevpage = $page - 1;
// show < link to go back to 1 page
echo " <a href='/?page_id=347?page=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around page
for ($x = ($page - $range); $x < (($page + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on page...
if ($x == $page) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='/?page_id=347?page=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($page != $totalpages) {
// get next page
$nextpage = $page + 1;
// echo forward link for next page
echo " <a href='/?page_id=347?page=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='/?page_id=347?page=$totalpages'>>></a> ";
} // end if
?>

php search pagination is not working

i can make pagination by query database and it works just fine. but when i use form to search from database, i can only get the first page data, the next page data won't show up.
i just cannot figure out how to maintain the search query..
this is my code. the problem should be in the url links in the pagination, but i just cannot see the problem
<?php
require('koneksi.php');
if(isset($_GET['search'])) {
$search = $_GET['search'];
$keyword = $_GET['keyword'];
$koneksi = mysqli_connect("localhost","root","","mycompany");
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM product WHERE deskripsi LIKE '%" . $keyword . "%'";
$result = mysqli_query($koneksi,$sql);
$rss = mysqli_fetch_row($result);
$numrows = $rss[0];
//numbers or rows to show per page
$rowperpage = 6;
//find out total pages
$totalpages = ceil($numrows/$rowperpage);
//get the current page or set default
if(isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page number
$currentpage = 1;
} // end if
// if the current page is greater than total pages...
if($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than total pages...
if($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowperpage;
$sql = "SELECT * FROM product WHERE deskripsi LIKE '%" . $keyword . "%' LIMIT $offset, $rowperpage";
$result = mysqli_query($koneksi, $sql);
// while there are rows to be fetched
while ($list = mysqli_fetch_assoc($result)) {
// echo data
echo $list['product_code'];
echo "<br>";
echo $list['deskripsi'];
}
/****** build the pagination links ******/
// range of num links to show
$range = 6;
$url = "searchbar.php";
// if not on page 1, don't show back links
if($currentpage > 1) {
// show << link to go to page 1
echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1'> << </a>";
//get previous page num
$prevpage = $currentpage - 1;
} // end if
echo " <li class='arrow'><a href='$url?currentpage=prevpage?&keyword=$keyword?cari=$cari'>«</a></li> ";
for($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it is a valid page number
if(($x > 0) && ($x <= $totalpages)) {
// if we are on current page
if($x == $currentpage) {
echo "<li class=''><a href=''> $x </a></li>";
} else {
// make it a link
//echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'> $x </a> ";
//echo "<li class=''><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x </a></li>";
echo "<li class=''><a href='$url?currentpage=$x?&keyword=$keyword?cari=$cari'> $x </a></li>";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <li class='arrow'><a href='$url?currentpage=$nextpage?&keyword=$keyword?cari=$cari'>»</a></li> ";
// echo forward link for lastpage
// echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'> >> </a> ";
} // end if
} // end if get search
require('footer.php');
?>
Looks like there could be a couple things missing here. For instance:
echo " <li class='arrow'><a href='$url?currentpage=prevpage?&keyword=$keyword?cari=$cari'>«</a></li> ";
in this line you are missing a $ for the prevpage: $prevpage but the querystring in the URL should only start with a ? and not contain question marks elsewhere, so this line should read more like
echo " <li class='arrow'><a href='$url?currentpage=$prevpage&keyword=$keyword&cari=$cari'>«</a></li> ";
I'm not 100% sure if that's going to fix your issue, but there is one big thing that I would ask you to look into before actually using this code anywhere and that's the SQL Injection that you have in your query.
You might read a bit of How can I prevent SQL injection in PHP? to get a better idea of how to rewrite your sql queries.
So, checkout your links, make sure the querystring is formatted correctly (http://host.com/script.php?querystring=something&var2=anothervar) where variables are separated only by &
As #aaronott pointed out, most of your links are wrong.
You are using cari=$cari which is not set anywhere, while in fact I guess you should add search=1 (or search=$search, but it's not really useful).
Also, you cannot have more than on ? in your querystring, so fix all your links like this:
...
if($currentpage > 1) {
echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1&search=1&keyword=$keyword'> << </a>";
$prevpage = $currentpage - 1;
}
echo " <li class='arrow'><a href='$url?currentpage=$prevpage&search=1&keyword=$keyword'>«</a></li> ";
...
if($x == $currentpage) {
echo "<li class=''><a href=''> $x </a></li>";
} else {
echo "<li class=''><a href='$url?currentpage=$x&search=1&keyword=$keyword'> $x </a></li>";
} // end else
...
echo " <li class='arrow'><a href='$url?currentpage=$nextpage&search=1&keyword=$keyword'>»</a></li> ";

Pagination not showing any results after 1st page

I'm using this pagination script, and it is showing the correct number of records for the first page, and the correct number of page links. When i click a page link however, the other pages show no records or page links at all.
Can anyone see where the problem is?
Thanks for looking.............
if(isset($_GET['brand'])){
$brand = $_GET['brand'];
$sql = mysqli_query($link, "SELECT COUNT(id) FROM products WHERE brand = '$brand'
AND status = 1 ORDER BY id DESC") OR die(mysqli_error($link));
$r = mysqli_fetch_row($sql);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 1;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];}
else {
// default page num
$currentpage = 1;} // end if
if ($currentpage > $totalpages) {
$currentpage = $totalpages;} // end if
// if current page is less than first page...
if ($currentpage < 1) {
$currentpage = 1;} // end if
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = mysqli_query($link, "SELECT *FROM products WHERE brand = '$brand' AND
status 1 ORDER BY id DESC LIMIT $offset, $rowsperpage") OR
die(mysqli_error($link));
echo"<div class='brandheading'>",
$brand,
"</div>";
if (!mysqli_num_rows($sql)){
echo 'No Products Match That Brand';}
else{
/****** build the pagination links ******/
echo" <div class='pagination'>";
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
}
else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
echo"</div>";
while($row = mysqli_fetch_array($sql)){
$data = $row['image'];
$file = substr($data, strpos($data, "/") + 1);
echo "<div class='featuredproduct'>",
"<a class='featuredlink' href='products.php?product=" . $row['id'] . "'>",
"<div class='productimage'>",
"<img class='featuredproductimage' src='$file' alt='{$row['name']} Image'
/>",
"</div>",
"<div class='featuredproductname'>{$row['name']}</div>",
"<div class='featuredproductprice'>&pound{$row['price']}</div>",
"</a>",
"</div>";
}
}
}
When going to next and/or previous pages you are not passing the brand.
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
should be
echo " <a href='{$_SERVER['PHP_SELF']}?brand=$brand&currentpage=1'><<</a> ";

How to continue numbered list in all next pages with pagination?

I am trying to display data in an ordered list with pagination in php. It is working fine on page one but on next page, the list starts again from 1 instead of continuing from previous number.
Here is my code:
<?php
// find out how many rows are in the table
$sql01 = mysql_query("SELECT COUNT(*) FROM pm,pm_reply");
$r = mysql_fetch_row($sql01);
$numrows = $r[0];
$rowsperpage = 3;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
}
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
}
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
}
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
// while there are rows to be fetched...
$sql=mysql_query("select *from pm where send_to='$_GET[name]' limit $offset, $rowsperpage");
$sql2=mysql_query("select *from pm_reply where send_to='$_GET[name]' limit $offset, $rowsperpage");
echo "<ol>";
while($rows=mysql_fetch_assoc($sql)) {
echo"<li>From: <a href='profile.php?name=$rows[send_by]'>$rows[send_by]</a><br><br><a style='text-decoration:none; font-size:14pt;' href='view_pm.php?name=$_GET[name]&pm=$rows[subject]'>$rows[subject]</a></li>";
echo "<hr>";
echo "<br>";
}
while($rows2=mysql_fetch_assoc($sql2)) {
echo"<li>From: <a href='profile.php?name=$rows2[replied_by]'>$rows2[replied_by]</a><br><br><a style='text-decoration:none; font-size:14pt;' href='view_pm.php?name=$_GET[name]&pm=$rows2[subject]'>$rows2[subject]</a></li>";
echo "<hr>";
echo "<br>";
}
echo "</ol>";
echo "</div>";
//End Div Content
echo "<div style='clear:both;'></div>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<div id='pagelinks'>";
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?name=$_GET[name]&currentpage=1'>First...</a> ";
// get previous page num
$prevpage = $currentpage - 1;
}
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
// if we're on current page...
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
} else {
// if not current page...
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?name=$_GET[name]&currentpage=$x'>$x</a> ";
}
}
}
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?name=$_GET[name]&currentpage=$totalpages'>...Last</a> ";
}
Just add start="$offset" to your echo "<ol>"; line.
echo "<ol start='$offset'>";

Using a count ++ function with pagination

The HTML table below is paginated. On page one, $count++ starts at one and then goes up, which is what I want.
The problem is that when I click on page two, $count++ starts at one again.
How can I make it start at 101 on page two?
$presult = mysql_query("SELECT COUNT(*) FROM login") or die(mysql_error());
$rr = mysql_fetch_row($presult);
$numrows = $rr[0];
$rowsperpage = 100;
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$tzFrom3 = new DateTimeZone('America/New_York');
$tzTo3 = new DateTimeZone('America/Phoenix');
$sqlStr3 = "SELECT
loginid,
username,
created,
activated
FROM login
WHERE activated = 1
ORDER BY created ASC
LIMIT $offset, $rowsperpage";
$result = mysql_query($sqlStr3);
$arr = array();
echo "<table>";
while ($row = mysql_fetch_array($result)) {
$dt3 = new DateTime($row["created"], $tzFrom3);
$dt3->setTimezone($tzTo3);
echo '<tr class="backgroundnonttsu">';
echo '<td>'.$count++.'</td>';
echo '<td >'.stripslashes($row["username"]).'</a></td>';
echo '<td >'.$dt3->format('F j, Y').'</td>';
echo '</tr>';
}
echo "</table>";
$range = 3;
/****** build the pagination links ******/
// range of num links to show
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=1' class='links'><<</a></div> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$prevpage' class='links'><</a></div> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " <div class='pages'>[<b>$x</b>] </div>";
// if not current page...
} else {
// make it a link
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$x' class='links'>$x</a></div> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$nextpage' class='links'>></a></div> ";
// echo forward link for lastpage
//echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$totalpages' class='links'>>></a></div> ";
} // end if
/****** end build pagination links ******/
if($currentpage==1){
$count=1;
}else{
$count =1+($currentpage*$rowsperpage);
}
Just do
$count = $offset + 1
right after you set offset. You only need one line of code.

Categories