I have made a script for Pagination and it can be displayed.
I will be a problem when the Next Button is pressed, the Pagination can't continue to the next page.
when the url has changed but the page remains in the first place.
eg:
[1]. http:// localhost /pagination/
This works and can display data 1-10 on page 1.
[2] http:// localhost /pagination/?page=2
paging should've been on page 2, but the data shown is 1-10 (supposedly 11-20)
This is the code:
// data_students.php
<?php
require 'conn.php';
open_conn();
?>
<table class="table table-condensed table-bordered table-hover" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th style="width:20px">No</th>
<th style="width:120px">NIM</th>
<th style="width:200px">Name</th>
<th>Address</th>
<th style="width:120px">Room</th>
<th style="width:120px">Status</th>
<th style="width:40px"></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$num_pages = 10;
$num_data = mysql_num_rows(mysql_query("SELECT * FROM students"));
$total_page = ceil($num_data / $num_pages);
// query searching
if(isset($_POST['search'])) {
$key = $_POST['search'];
echo "<strong>Search results for keyword: $key</strong>";
$query = mysql_query("
SELECT * FROM students
WHERE nim LIKE '%$key%'
OR name LIKE '%$key%'
OR address LIKE '%$key%'
OR room LIKE '%$key%'
OR status LIKE '%$key%'
");
// query if the specified page number
} elseif(isset($_GET['page']) && $_GET['page']!="") {
$page = $_GET['page'];
$i = ($page - 1) * $num_pages + 1;
$query = mysql_query("SELECT * FROM students ORDER BY name ASC LIMIT ".(($page - 1) * $num_pages).", $num_pages");
// query when there is no parameter page and search
} else {
$query = mysql_query("SELECT * FROM students ORDER BY name ASC LIMIT 0, $num_pages");
}
// show database students
while($data = mysql_fetch_array($query)) {
if($data['status']==1) {
$status = "Active";
} else {
$status = "Off";
}
?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $data['nim'] ?></td>
<td><?php echo $data['name'] ?></td>
<td><?php echo $data['address'] ?></td>
<td><?php echo $data['room'] ?></td>
<td><?php echo $status ?></td>
<td>
<a href="#dialog-students" id="<?php echo $data['kd_mhs'] ?>" class="change" data-toggle="modal">
<i class="icon-pencil"></i>
</a>
<a href="#" id="<?php echo $data['kd_mhs'] ?>" class="delete">
<i class="icon-trash"></i>
</a>
</td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<?php if(!isset($_POST['search'])) { ?>
<!-- to display the menu page -->
<div class="pagination pagination-right">
<ul>
<?php for($i = 1; $i <= $total_page; $i++) { ?>
<li class="page" id="<?php echo $i ?>"><?php echo ''.$i.'' ;?></li>
<?php } ?>
</ul>
</div>
<?php } ?>
<?php
close_conn();
?>
this is jquery:
// students-app.js
(function($) {
// function is executed after the entire document is displayed
$(document).ready(function(e) {
var kd_mhs = 0;
var main = "data_students.php";
// show data students from data_students.php in index.php <div id="data-students"></div>
$("#data-students").load(main);
// when the search inputbox filled
$('input:text[name=searching]').on('input',function(e){
var v_search = $('input:text[name=searching]').val();
if(v_search!="") {
$.post(main, {search: v_search} ,function(data) {
$("#data-students").html(data).show();
});
} else {
$("#data-students").load(main);
}
});
// when the button page is pressed
$('.page').live("click", function(event){
// take the value of the inputbox
kd_page = this.id;
$.post(main, {page: kd_page} ,function(data) {
$("#data-students").html(data).show();
});
});
});
}) (jQuery);
Related
I am trying to do a pagination for category result page which is listing articles with ajax.
I use where clause and need to pass article id to the ajax page.
My codes : ajax.php
include_once '../db.php';
include_once '../class/Articles.php';
$ArticleHandler = new Articles($pdo);
if (!(isset($_GET['pageNumber']))) {
$pageNumber = 1;
} else {
$pageNumber = $_GET['pageNumber'];
}
$perPageCount = 5;
$catid = $_POST['article_id'];
$sql = "SELECT * FROM posts WHERE pcat = ?";
$posts = $ArticleHandler->getPosts($sql, [$catid])->fetchAll();
if ($posts !== '0') {
$rowCount = $ArticleHandler->getPosts("SELECT count(*) FROM posts")->fetchColumn();
}
$pagesCount = ceil($rowCount/$perPageCount);
$lowerLimit = ($pageNumber - 1) * $perPageCount;
$sql = "SELECT * FROM posts WHERE pcat = :pcat ORDER BY pid DESC LIMIT :offset, :limit";
$results = $ArticleHandler->getPosts($sql, array(':pcat'=>$catid, ':offset'=>$lowerLimit, ':limit'=>$perPageCount))->fetchAll();
?>
<table class="table table-hover table-responsive">
<tr>
<th align="center">Name</th>
<th align="center">Experience<br>(in years)
</th>
<th align="center">Subject</th>
</tr>
<?php foreach ($results as $data) { ?>
<tr>
<td align="left"><?php echo $data['ptitle'] ?></td>
</tr>
<?php
}
?>
</table>
<div style="height: 30px;"></div>
<table width="50%" align="center">
<tr>
<td valign="top" align="left"><?php echo $catid; ?></td>
<td valign="top" align="center">
<?php
for ($i = 1; $i <= $pagesCount; $i ++) {
if ($i == $pageNumber) {
?>
<?php echo $i ?>
<?php
} else {
?>
<a href="javascript:void(0);" class="pages"
onclick="showRecords('<?php echo $perPageCount; ?>', '<?php echo $i; ?>');"><?php echo $i ?></a>
<?php
}
}
?>
</td>
<td align="right" valign="top">
Page <?php echo $pageNumber; ?> of <?php echo $pagesCount; ?>
</td>
</tr>
</table>
And index.php
<div id="results"></div>
<div id="loader"></div>
Ajax codes :
function showRecords(perPageCount, pageNumber) {
$.ajax({
type: "GET",
url: "modules/ajax.php",
data: "pageNumber=" + pageNumber,
cache: false,
beforeSend: function() {
$('#loader').html('<img src="loader.png" alt="reload" width="20" height="20" style="margin-top:10px;">');
},
success: function(html) {
$("#results").html(html);
$('#loader').html('');
}
});
}
$(document).ready(function() {
showRecords(10, 1);
});
My tries : I've added a div with artcile id to index.php and used attr to pass it to ajax but couldn't pass it to the page.
Try passing the article id along with pageNumber that you are passing in GET request.
data: {pageNumber : YOUR_PAGE_NUMBER, articleId: ARTICLE_ID}
Do not forget to pass the articleId as 3rd parameter to the function.
I am implementing a website in which admin has access to maintain stock. I am displaying stock from the database in html table. i have used pagination to display 10 records per page. I want that when i am on page 1 it displays "Showing 1-10 of total record" and when i am on page 2 it displays "Showing 11-20 of total record" and vice versa.
CODE:
<?php
$link = mysql_connect("localhost", "root", "");
mysql_select_db("login", $link);
$result = mysql_query("SELECT COUNT(*) FROM add_stock");
$row = mysql_fetch_row($result);
$num = $row[0];
?>
<table align="center" border="0" id="myTable" class="table table-striped table-bordered table-list">
<tr>
<th>Sr.No</th>
<th>Product Code</th>
<th>Brand</th>
<th>Price</th>
<th>Gender</th>
<th>Category</th>
<th>Material</th>
<th>Size</th>
<th>Description</th>
<th>Quantity</th>
<th><b>Image</b></th>
</tr>
$num_rec_per_page=10;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$sql = "SELECT * FROM add_stock ORDER BY id DESC LIMIT $start_from, $num_rec_per_page";
$rs_result = mysql_query ($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
$next_page = $page + 1;
$prev_page = $page - 1;
$i= $start_from;
$start=1;
while ($result=mysql_fetch_array($rs_result) )
{
?>
<tr>
<td><?php echo $i+$start; ?></td>
<td><?php echo $result['id']; ?></td>
<td><?php echo $result['brand_name']; ?></td>
<td><?php echo $result['price']; ?></td>
<td><?php echo $result['gender_name']; ?></td>
<td><?php echo $result['category_name']; ?></td>
<td><?php echo $result['material_name']; ?></td>
<td><?php echo $result['size_name']; ?></td>
<td><?php echo $result['dress_description']; ?></td>
<td><?php echo $result['dress_quantity']; ?></td>
<td><a href="javascript:window.open('<?php echo $result['image'] ?>','mypopuptitle', '_parent')" >View Image</a></td>
</tr>
<?php
$i++;
} ?>
</table>
<?php
$sql = "SELECT * FROM add_stock";
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
?>
<div style="margin-left: 5px;">
<div class="pagination">
<?php
echo "<a href='viewstock.php?page=1'><b>«</b></a>";
if ($page==1) {
$page=1;
}
else{
echo "<a href='viewstock.php?page=$prev_page'><b>Prev</b></a>"; }
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='viewstock.php?page=".$i."'><b>".$i."</b></a>";
}
if ($page==$total_pages) {
$page=$total_pages;
}
else{
echo "<a href='viewstock.php?page=$next_page'><b>Next</b></a>"; }
echo "<a href='viewstock.php?page=$total_pages'><b>»</b></a> ";
?>
</div>
</div>
<p>Displaying <?php echo $start ?> - <?php echo $total_records ?> of Records: <?php echo $num ?></p>
This will work:
<p>Displaying <?php echo $start_from+1 ?> - <?php echo $start_from + $total_records ?> of Records: <?php echo $num ?></p>
as long as you:
1) Move the output below the code where the numbers you need are calculated
2) Don't re-use the variable $total_records after your SELECT * FROM add_stock. Instead give this instance of the variable a new name so it can't be confused with the earlier version, which means something different, and is needed for your output.
Please note also my first comment regarding your SQL Injection vulnerability, which you should take steps to fix as soon as possible.
This is my code for the search, it works fine when the notification function is not added. But once i added "Notification" function it would not make this "Search" function work. please help
Edit: i added the code on how i am showing the data of the table where i have the search function.
$(document).ready(function(){
$("#search").keyup(function(){
if( $(this).val() != "")
{
$("#table tbody>tr").hide();
$("#table td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
$("#table tbody>tr").show();
}
});
});
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
then this is the Html code for its input
<input type="search" id="search" class = "search" name = "search" placeholder="Search...">
then this is the code on how i populate the table in my page
<label id = "title">Manage Licenses</label><br/>
</div>
</div>
<div class="row" style = "padding-bottom : 20px;">
<?php
$qry = $con->prepare("SELECT * FROM tbllicense, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate");
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$expiredcount = 0;
?>
<table class = "table" id = "table">
<thead>
<th>Record ID</th>
<th>Name</th>
<th>Email</th>
<th>License Type</th>
<th>Expiration</th>
<th>Options</th>
<tbody>
<?php
foreach ($rows as $row) {
?>
<tr>
<td><?= $row["Request_ID"] ?></td>
<td><?= $row["txtFName"] . " " . $row["txtSurname"] ?></td>
<td><?= $row["txtEmail"] ?></td>
<td><?= $row["txtLicense"] ?></td>
<td><?= date("M d, Y", strtotime($row["ExpirationDate"])) ?></td>
<td><input type = "button" class = "btnAccept" value = "Renew" onclick = "renew(<?= $row["Request_ID"] ?>)"/></td>
</tr>
<?php
}
?>
</thead>
</tbody>
</table>
</div>
When i add this funtion (Notification). The search would not work properly and when i put an input in the search form, the results will just be blank.
<li style = "float:right">
<div style = "float:right">
<?php
$qry = $con->prepare("SELECT * FROM tbllicense, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted'
UNION
SELECT * FROM tblvisa, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate"
);
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
if ($qry->rowCount()) {
echo '<img width=15 height=13 src="img/alert.png" />';
}
?>
</div>
<a href='#' id = "notificationLink" class = "notificationLink" title = "Notification"><img src="img/notification.png"
style = " position : relative; width : 15px; height : 13px;"/></a>
<div id="notificationContainer">
<div id="notificationTitle">Notifications</div>
<div id="notificationBody" class="scrollbar2">
<?php
$qry = $con->prepare("SELECT * FROM tbllicense, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate");
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$expiredcount = 0;
?>
<table class = "table" id = "table">
<thead>
<?php
foreach ($rows as $row) {
$expiredcount++;
?>
<tr>
<td><a href='_admin_business_license.php' style = "color: white;" class = "link">The Request <?= $row["Request_ID"] ?> is expired or about to expire on
<?= date("M d, Y", strtotime($row["ExpirationDate"])) ?> from the Business License</a></td>
</tr>
<?php
}
?>
<?php
$qry = $con->prepare("SELECT * FROM tblvisa, tblrequests WHERE ExpirationDate < DATE_ADD(NOW(), INTERVAL 2 MONTH) AND
tblrequests.ID = Request_ID AND tblrequests.Status = 'accepted' ORDER BY ExpirationDate");
$qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_ASSOC);
$expiredcount1 = 0;
?>
<?php
foreach ($rows as $row) {
$expiredcount1++;
?>
<tr>
<td><a href='_admin_visa.php' style = "color: white" class = "link">The Request <?= $row["Request_ID"] ?> is expired or about to expire on
<?= date("M d, Y", strtotime($row["ExpirationDate"])) ?> from the Visa</a></td>
</tr>
<?php
}
?>
</thead>
</table>
</div>
<div id="notificationFooter">See All</div>
</div>
</li>
Your search function is searching in tbody but you only have thead in your code.
Unless there is more code we don't see (which i doubt since you close the table) then i think that is the problem
change
$("#table tbody>tr").hide();
to
$("#table thead>tr").hide();
and
$("#table tbody>tr").show();
to
$("#table thead>tr").show();
You also need to do the following
$(document).ready(function(){
$("#search").keyup(function(){
var txtVal = $(this).val();
if(txtVal != "")
{
$("#table > thead > tr").show();
$.each($("#table > thead > tr"), function (i, o) {
var match = $("td:contains-ci('" + txtVal + "')",this)
if (match.length > 0) $(this).show();
else $(this).hide();
});
}
else
{
$("#table thead > tr").show();
}
});
});
Thank you very much for those who answered my questions :)
i found out the reason why its leaving a blank page is because im searching for the same "table" of Notification and the admin page.
i changed the id of the "table"(s) causing conflict to the code of Search.
$("#search").keyup(function(){
if( $(this).val() != "")
{
$("#searchtable tbody>tr").hide();
$("#searchtable td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
$("#table tbody>tr").show();
}
});
});
this is the new id for the table that the search must run through
<table class = "table" id = "searchtable">
<thead>
<th>Record ID</th>
<th>Name</th>
<th>Email</th>
<th>License Type</th>
<th>Expiration</th>
<th>Options</th>
<tbody>
<?php
foreach ($rows as $row) {
?>
<tr>
<td><?= $row["Request_ID"] ?></td>
<td><?= $row["txtFName"] . " " . $row["txtSurname"] ?></td>
<td><?= $row["txtEmail"] ?></td>
<td><?= $row["txtLicense"] ?></td>
<td><?= date("M d, Y", strtotime($row["ExpirationDate"])) ?></td>
<td><input type = "button" class = "btnAccept" value = "Renew" onclick = "renew(<?= $row["Request_ID"] ?>)"/></td>
</tr>
<?php
}
?>
</thead>
</tbody>
</table>
I have an infinite scroll scipt that is pulling data and displaying it just fine. However, I am finding that when you scroll down the data pull starts again at the beginning. Right now I have 8 rows for testing in the database to make it easy. My control to get the next data set does not seem to be working otherwise it would go to the next set of results?
//item per page
$limit = 5;
$page =(int)(!isset($_GET['p']))?1: $_GET['p'];
// sql query
$sqlContent="SELECT make, model, year, carid FROM cars";
//Query start point
$start =($page * $limit)- $limit;
$resContent=$DB_con->query($sqlContent);
$rows_returned= $resContent->rowCount();//->fetchColumn();
// query for page navigation
if( $rows_returned > ($page * $limit)){
$next =++$page;
}
$sqlContent = $sqlContent ." LIMIT $start, $limit";
$finalContent = $DB_con->query($sqlContent);
if($finalContent === false) {
trigger_error('Error: ' . $DB_con->error, E_USER_ERROR);
} else {
$rows_returned= $finalContent->rowCount();//->fetchColumn();
}
?>
then display the results:
<?php while($rowContent = $finalContent->fetch()) {
$year = $rowContent['year'];
$make = $rowContent['make'];
$model = $rowContent['model'];
?>
<div class="row">
<div class="ride"><?php echo "$year $make $model"; ?></div>
</div>
<?php } ?>
</div>
</div>
<!--page navigation-->
<?php if(isset($next)):?>
<div class="nav">
<a href='index.php?p=<?php echo $next?>'>Next</a>
</div>
<?php endif ?>
</div>
This is something that I adapted for PHP from my days as a classic-asp programmer.
It provides a nice counter along with First, Last, Next & Previous links.
First is your sql query with two select statements depending on the number of records you want to show per page AND the total number of records. (in case the number you want to show is actually larger than the number of records in the db).
<?php
require'connections/conn.php';
$maxRows_rsList = 10; // the number of records you want to show per page
$pageNum_rsList = 0;
if (isset($_GET['pageNum_rsList'])) {
$pageNum_rsList = $_GET['pageNum_rsList'];
}
$startRow_rsList = $pageNum_rsList * $maxRows_rsList;
$query_rsList = $conn->prepare("SELECT make, model, year, carid FROM cars");
$query_limit_rsList = $conn->prepare("SELECT make, model, year, carid FROM cars LIMIT $startRow_rsList, $maxRows_rsList");
$query_limit_rsList->execute();
$row_rsList = $query_limit_rsList->fetch(PDO::FETCH_ASSOC);
if (isset($_GET['totalRows_rsList'])) {
$totalRows_rsList = $_GET['totalRows_rsList'];
} else {
$all_rsList = $query_rsList->execute();
$totalRows_rsList = $query_rsList->rowCount();
}
$totalPages_rsList = ceil($totalRows_rsList/$maxRows_rsList)-1;
$queryString_rsList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsList") == false &&
stristr($param, "totalRows_rsList") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsList = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsList = sprintf("&totalRows_rsList=%d%s", $totalRows_rsList, $queryString_rsList);
$currentPage = $_SERVER["PHP_SELF"]; // so we stay on the same page just changing the recordset data
?>
Then our output
<table cellpadding="5" cellspacing="0" border="0">
<?php if($totalRows_rsList > $maxRows_rsList) { ?>
<tr>
<td colspan="2"><?php echo ($startRow_rsList + 1) ?> to <?php echo min($startRow_rsList + $maxRows_rsList, $totalRows_rsList) ?> of <?php echo $totalRows_rsList ?> cars<br />
<table border="0">
<tr>
<?php if ($pageNum_rsList > 0) { // Show if not first page ?>
<td width="25" nowrap="nowrap">
First
</td>
<?php } // Show if not first page ?>
<?php if ($pageNum_rsList > 0) { // Show if not first page ?>
<td width="25" nowrap="nowrap">
Prev
</td>
<?php } // Show if not first page ?>
<?php if ($pageNum_rsList < $totalPages_rsList) { // Show if not last page ?>
<td width="25" nowrap="nowrap">
Next
</td>
<?php } // Show if not last page ?>
<?php if ($pageNum_rsList < $totalPages_rsList) { // Show if not last page ?>
<td width="25" nowrap="nowrap">
Last
</td>
<?php } // Show if not last page ?>
</tr>
</table></td>
</tr>
<?php } else if(($totalRows_rsList == $maxRows_rsList) || ($totalRows_rsList < $maxRows_rsList)) { ?>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2"><?php echo ($startRow_rsList + 1) ?> to <?php echo min($startRow_rsList + $maxRows_rsList, $totalRows_rsList) ?> of <?php echo $totalRows_rsList ?> cars<br /></td></tr>
<?php } ?>
<tr><td>
<?php do {
$year = $row_rsList['year'];
$make = $row_rsList['make'];
$model = $row_rsList['model'];
?>
<div class="row">
<div class="ride"><?php echo "$year $make $model"; ?></div>
</div>
<?php } while($row_rsList = $query_limit_rsList->fetch(PDO::FETCH_ASSOC)) ?>
</div>
</div>
</td></tr>
</table>
$page =(int)(!isset($_GET['p']))?1: $_GET['p'];
should actually be
$page =(!isset($_GET['p']))?1: (int)$_GET['p'];
what you are doing is casting the boolean result of isset as an integer
I have a page which displays number of records on each page. I am displaying 5 records on each page and then next 5 on the next page and so on. Paging is working fine but the problem is on first page I'm displaying number serial wise next to each record i.e. from 1 to 5. Then on next page it should display numbers from 6 to 10 and on next page 11 to 15 and so on. But on every page numbers start from 1 to 5.
My code is below. I have tried different strategies but nothing worked. Please check code and tell me where to make changes so that it works properly. Thanks a ton in advance.
<div class="grid_12">
<div class="box first round fullpage mh500 grid">
<h2><?php echo $resource->_pageHead; ?></h2>
<?php $resource->displayMessage(); ?>
<?php
if($resource->_recordCount > 0)
{
?>
<div class="block">
<table class="listing" >
<thead>
<tr>
<th width="50" class="bdr-left">Sr. No.</th>
<th width="60">Name</th>
<th width="60">Email</th>
<th width="60">Address</th>
<th width="60">City</th>
<th width="60">State</th>
<th width="60">Phone Number</th>
<th width="60">Country</th>
<th width="60">Comment</th>
<th width="60">Inquiry Date</th>
<th width="60" class="bdr-right">Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$_SESSION['number'] = $i;
$perpage = 5;
$q = mysql_query("SELECT * FROM $resource->_table");
$total_record = mysql_num_rows($q);
$pages = ceil($total_record/$perpage);
$page = (isset($_GET['page']))?$_GET['page']:1;
$start = ($page-1) * $perpage;
$result = mysql_query("SELECT * FROM $resource->_table LIMIT $start, $perpage");
while($res = mysql_fetch_array($result))
{
?>
<tr class="odd gradeX">
<td><?php echo $i; ?></td>
<td><?php echo $res['name']; ?></td>
<td><?php echo $res['email'];?></td>
<td><?php echo $res['address'];?></td>
<td><?php echo $res['city'];?></td>
<td><?php echo $res['state'];?></td>
<td><?php echo $res['p_code']."-".$res['p_num'];?></td>
<td><?php echo $res['country'];?></td>
<td><?php echo substr($res['comments'], 0, 100);echo "...";?></td>
<td><?php echo $res['inquiry_date'];?></td>
<td align="center">
<a href="<?php echo $_SERVER['PHP_SELF'].'?action=delete&id='.$res['id'];?>" onclick="return confirm('Do you want to delete this record?');">
<img src="img/cross.png" alt="Delete" title="Delete"/>
</a>
</td>
</tr>
<?php
$i++;
}
}
?>
</tbody>
</table>
</div>
<div id="paging" style="padding-left:500px;">
<?php
$prev=$page-1;
$next=$page+1;
if($prev > 0)
{
echo "<a href='?page=$prev'>Prev</a>";
}
echo " ";
if($pages >= 1 AND $page <= $pages)
{
for($x=1;$x<=$pages;$x++)
{
echo " ";
echo ($x==$page) ?"$x":'<a href="?page='.$x.'" >'.$x.'</a>';
}
echo "  ";
if($page<$pages)
{
echo "<a href='?page=$next'>Next</a>";
}
}
?>
</div>
</div>
<div class="clear"></div>
</div>
I hope the following logic would be helpful to you, initialize a variable $i = 0;
Calculate the starting number of a record by the following logic,
$page_num = (int) (!isset($_GET['page']) ? 1 : $_GET['page']);
$start_num =((($page_num*$num_records_per_page)-$num_records_per_page)+1);
initialize a variable $i = 0;
Then inside the loop calculate the serial number like,
$slNo = $i+$start_num;
Then echo $slNo;
instead of echo $i; try this
$j= (($page-1) * $perpage) + i; echo $j;
You can go to this website and there is a simple example of pagination
http://snipplr.com/view/55519/
hope this works for you.