For the past 2 days I've been looking for a pagination script of sorts, and I found this one which I'm starting to implement on my website.
The code is the following:
<?php
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$data = mysqli_query($lig,"SELECT * FROM requisicao") or die("data");
$rows = mysqli_num_rows($data);
$page_rows = 5;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysqli_query($lig,"SELECT * FROM requisicao $max") or die("data_p");
while($info = mysqli_fetch_assoc( $data_p ))
{
?>
<tr>
<td><?php print $info['id_requisicao']; ?> </td>
<td><?php print $info['username']; ?> </td>
<td><?php print $info['nome_servico']; ?> </td>
<td><?php print $info['data_requisicao']; ?> </td>
<td><?php print $info['estado_requisicao']; ?> </td>
<td><?php print $info['prioridade']; ?> </td>
<td><?php print $info['total']; ?> </td>
<td align="center">+</td>
<tr>
<?php
}
?>
</tbody>
</table>
<?php
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-Início</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Anterior</a> ";
}
echo " ---- ";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Seguinte -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Última ->></a> ";
}
?>
I'm getting the first 5 rows out of it, but when I press Seguinte (which is Next) it changes the link (TO PAGE 2) but it doesn't change the values that get outputed. Basically, it always shows page 1.
I've also looked into several similar questions but I haven't found solutions that fix my problem.
Thanks in advance, and my apologies if this is a simple problem and I'm just overlooking things :s
The problem is that $pagenum will be initialized as 1, anyway.
Instead of:
if (!(isset($pagenum)))
{
$pagenum = 1;
}
Try writing this:
if (!isset($_REQUEST['pagenum']) || !is_int($_REQUEST['pagenum']))
{
$pagenum = 1;
} else {
$pagenum = (int)$_REQUEST['pagenum'];
}
You may find some more info handling HTTP Request variables here
Related
code:
<table>
<tr style="background: white url(bg.gif) repeat-x left top;color: #fff;">
<th>College Id</th>
<th>College Name</th>
<th>Website</th>
<th>Field</th>
<th>City</th>
<th>Action</th>
</tr>
<?php
$per_page=10;
if (isset($_GET["page"]))
{
$page = $_GET["page"];
}
else {
$page=1;
}
$start_from = ($page-1) * $per_page;
$sql="select * from all_colleges LIMIT $start_from, $per_page";
$result = mysqli_query($link,$sql);
while ($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['college_id']; ?></td>
<td><?php echo $row['college_name']; ?></td>
<td><?php echo $row['website']; ?></td>
<td><?php echo $row['field']; ?></td>
<td><?php echo $row['city']; ?></td>
<td>
<a class='view' title='view' href='view.php?id=<?php echo $row['college_id']; ?>'>
<img src='gridview/view.png' alt='view' />
</a>
<a class='update' title='Update' href='update.php?id=<?php echo $row['college_id']; ?>'>
<img src='gridview/update.png' alt='Update' />
</a>
<a class='delete' title='delete' href='delete.php?ad_id=<?php echo $row['college_id']; ?>'>
<img src='gridview/delete.png' alt='delete' />
</a>
</td>
</tr>
<?php
}
?>
</table>
<div style="padding: 10px;">
<?php
$query = "select * from all_colleges";
$result = mysqli_query($link, $query);
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $per_page);
echo "<center><a href='admin.php?page=1' style='padding:5px;'>".'previous'."</a>";
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='admin.php?page=".$i."'>".$i."</a>";
}
echo "<a href='admin.php?page=$total_pages'>".'next'."</a></center>";
?>
</div>
In this code I want to create a pagination with next and previous button here this code is working properly but it show diffrent pagination i.e. if the number of results is 200 then it will display like
previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 next
but I want like
previous 1 2 3 4 5 ....8 9 next
How can I do this please help ?
Thank You
You can check each iteration of your loop if you want to display the number.
In the following code, only:
the first two pages
the last two pages
the current page
each two pages to the left and to the right of the current page
are displayed.
$skipped = false;
for ($i = 1; $i <= $total_pages; $i++) {
if ($i < 3 || $total_pages- $i < 3 || abs($page - $i) < 3) {
if ($skipped)
echo '<span> ... </span>';
$skipped = false;
echo "<a href='admin.php?page=" . $i . "'>" . $i . "</a>";
} else {
$skipped = true;
}
}
If you have a lot of pages, the big loop is unnecessary.
Instead, you could use three different loops:
$done = [];
for ($i = 1; $i < 3; $i++) {
$done[$i] = true;
//echo
}
if ($page > 3)
echo '<span> ... </span>';
for ($i = $page - 2; $i < $page + 3; $i++) {
if (isset($done[$i])
continue;
$done[$i] = true;
//echo
}
if ($page < $total_pages - 3)
echo '<span> ... </span>';
for ($i = $total_pages- 2; $i < $total_pages; $i++) {
if (isset($done[$i])
continue;
$done[$i] = true;
//echo
}
To fix your two other buttons (previous and next), link to $page - 1 and$page + 1 instead of 1 and $total_pages.
This question already has an answer here:
PHP Pagination removes search term and reverts back to displaying all results, fix?
(1 answer)
Closed 6 years ago.
Creating a new project using php: retrieving data from mysql database using a search function (search.php) - added pagination to the search result on results page (find.php). Question is, when the first search is displayed, it shows the correct data; however, when i click on 2nd page (pagination button), it populates all the data again - not the term i searched for: Please help!
search.php
<form action="find.php" method="post">
<input name="search" type="search" autofocus><input type="submit" name="button">
</form>
find.php
<?php
include_once("config.php");
if(isset($_POST['button'])){
$search=$_POST['search'];
}
$result = mysql_query(" SELECT * FROM bra_list WHERE locations like '%{$search}%' $limit ");
$row = mysql_num_rows($result);
$page_rows = 3;
$last = ceil($row/$page_rows);
if($last < 1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET['page'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['page']);
}
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$result = mysql_query(" SELECT * FROM bra_list WHERE locations like '%{$search}%' $limit ");
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
$paginationCtrls = '';
$self = $_SERVER['PHP_SELF'];
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= 'Previous';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= ''.$i.'';
}
}
}
$paginationCtrls .= '<span class="current">'.$pagenum.'</span>';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= ''.$i.'';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= 'Next ';
}
}
?>
<table border='1' cellpadding='10' style="border-collapse:collapse;">
<tr>
<th>id</th>
<th>name</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>website</th>
<th>locations</th>
<th>info</th>
</tr>
<?php
while($row = mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['website']; ?></td>
<td><?php echo $row['locations']; ?></td>
<td><?php echo $row['info']; ?></td>
</tr>
<?php
}
?>
You must have to set search term in pagination links. Try this.
<form action="find.php" method="post">
<input name="search" type="search" autofocus><input type="submit" name="button">
</form>
<?php
include_once("config.php");
if(isset($_POST['button'])){
$search=$_POST['search'];
}
$result = mysql_query(" SELECT * FROM bra_list WHERE locations like '%{$search}%' $limit ");
$row = mysql_num_rows($result);
$page_rows = 3;
$last = ceil($row/$page_rows);
if($last < 1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET['page'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['page']);
}
// get search tearm from url
if(isset($_GET['search'])){
$search=$_GET['search'];
}
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$result = mysql_query(" SELECT * FROM bra_list WHERE locations like '%{$search}%' $limit ");
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
$paginationCtrls = '';
$self = $_SERVER['PHP_SELF'];
// you must have to set search tearm in pagination links
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= 'Previous';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= ''.$i.'';
}
}
}
$paginationCtrls .= '<span class="current">'.$pagenum.'</span>';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= ''.$i.'';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= 'Next ';
}
}
?>
<table border='1' cellpadding='10' style="border-collapse:collapse;">
<tr>
<th>id</th>
<th>name</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>website</th>
<th>locations</th>
<th>info</th>
</tr>
<?php
while($row = mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['website']; ?></td>
<td><?php echo $row['locations']; ?></td>
<td><?php echo $row['info']; ?></td>
</tr>
<?php
}
?>
I have a pagination question. When I load this page in the browser and click on the category link to show my products the first page shows with the products limited and the links for pagination are in place but it keeps sending me to the first page which is zero for whatever pagination link I click on. But the odd thing is is when I change
$offset=($pageNum - 1) * $perPage;
to
$offset=($pageNum)= $perPage;
if shows the rest of the products I'm trying to show after clicking on the category. So the problem might be in the page or somewhere around there.
Here is my code.
<?php
$productUlList="";
error_reporting (E_ALL ^ E_NOTICE);
include_once "convenientglobal2localhost.php";
$result = mysql_query("SELECT * FROM category WHERE 1")or die(mysql_error());
while($rowp=mysql_fetch_array($result)){
$categoryId=$rowp['catId'];
$categoryName=$rowp['catName'];
$productUlList.='
<ul id="ul" >
<li id="lists"> '.$categoryName.' </li>
</ul>';
}
?>
<?php
$msg_to_user3='';
$productList.='';
$categoryList='';
include_once "convenientglobal2localhost.php";
$perPage= 3;
if(isset($_GET['category']))
$categoryNames=$_GET['category'];
$pageNum=(isset($_GET['page']))? (int)$_GET['page']: 1;
$pages_query= mysql_query("SELECT * FROM products INNER JOIN category ON categoryName=catName WHERE categoryName='$categoryNames'");
$numrows= mysql_num_rows($pages_query);
$maxpages=ceil($numrows / $perPage);
$offset=($pageNum-1) * $perPage;
if ($offset < 0)
{
$offset = 0 ;
}
include_once "convenientglobal2localhost.php";
$results = mysql_query("SELECT * FROM products WHERE categoryName='$categoryNames' LIMIT $offset, $perPage")or die(mysql_error());
$num=mysql_num_rows($results);
if($num > 0){
while($row=mysql_fetch_array($results)){
$productId=$row['productId'];
$productName=$row['name'];
$productDescription=$row['description'];
$productPrice=$row['price'];
$productDiscountedPrice=$row['discountedPrice'];
$productStock=$row['stock'];
$productCategory=$row['categoryName'];
$categoryId=$row['catId'];
$catName=$row['catName'];
$categoryList='<table><th id="toptable"></th></table>
<table id="categorytable">
<th><img src="inventory_category_images/' . $categoryId . '.jpg" width="498px"; height="125px";/></th>
</table>';
$productList.='<table id="productoutputtable">
<tr>
<td rowspan="7" valign="top"><img style="border-style=solid; border-color:#767475; padding=; "src="inventory_images/' . $productId . '.jpg" width="150" height="135"/>
</td>
</tr>
<tr>
<td id="tablecolor" ><strong>Product</strong></td>
<td colspan="2">' . $productName . ' </td>
<td id="tablecolor"><strong>Category</strong></td>
<td>' . $productCategory . ' </td>
</tr>
<tr>
<td id="tablecolor"><strong>Description:</strong></td>
<td colspan="3">' . $productDescription . ' </td>
</tr>
<tr>
<td id="tablecolor" ><strong>Price:</strong></td>
<td>$' . $productPrice . ' </td>
</tr><tr>
<td id="tablecolor"colspan="1"><strong>Sale Price:</strong></td>
<td>$' . $productDiscountedPrice . ' </td>
<td id="tablecolor"colspan="2"><strong>In Stock </strong></td>
<td>' . $productStock . ' </td>
</tr>
</table>';
}
$self= $_SERVER['PHP_SELF'];
for($page=1; $page<=$maxpages; $page++){
if($page == $pageNum){
$nav= "$page";
}
else{
$nav= "$page";
}
}
if($page > 1)
{
$page=$pageNum-1;
$prev ="[Prev]";
$first="[First Page]";
}
else
{
$prev= " ";
$first=" ";
}
if($pageNum < $maxPages)
{
$page=$pageNum+1;
$next ="[Next]";
$last="[Last Page]";
}
else
{
$next= " ";
$last=" ";
}
$pageList.= $first. $prev. $nav. $next. $last;
}
else{
$msg_to_user3="You have no products listed.";
}
//$pageList.="";
//for($i = 0 ; $i <= $maxpages ; $i++) {
//if($i == $page) {
//$pageList.= "<B>$i</B>";
//}else{
//$pageList.= ''.$i.'';
//
//}
//}
?>
Thanks for all you help!!!
I'll ignore the inefficiencies (refer to comments on your question). The problem is not your offsetting code—that works fine. Your links are broken.
When generating your numbered links into $nav, you need to append, not overwrite. Use .=, not =. Also, beware of capitalization. $maxpages is not $maxPages.
Here's updated code. Proof this works. Unless your database query is misconstructed (I can't test that, sorry!), you should be good to go.
$self= $_SERVER['PHP_SELF'];
for($page=1; $page<=$maxpages; $page++){
if($page == $pageNum){
$nav.= "$page";
}
else{
$nav.= "$page";
}
}
if($page > 1)
{
$page=$pageNum-1;
$prev ="[Prev]";
$first="[First Page]";
}
else
{
$prev= " ";
$first=" ";
}
if($pageNum < $maxpages)
{
$page=$pageNum+1;
$next ="[Next]";
$last="[Last Page]";
}
else
{
$next= " ";
$last=" ";
}
$pageList.= $first. $prev. $nav. $next. $last;
I've come across a problem but any help would be appreciated.
When I query the database using the results posted from a form, the pagination works initially i.e. for the first 10 records but when I click on the 2 hyperlink of the pagination for the second page of results it loses the $_POST variable and returns to the full data set.
What is the best way of keeping these variables available for the second (and further) pages?
The below is my complete php file.
<html>
<head>
<link rel="stylesheet" type="text/css"
href="design.css">
</head>
<body>
<?php
include("header.php");
?>
<center>
<div id="content" class="frm">
<a href='admin.php' style='float:left'>Back!</a>
<h2>Search Result</h2>
<br><br>
<?php
include("../config.inc");
$find=$_GET['find'];
// get page no and set it to page variable, if no page is selected so asign first page bydefualt
if (isset($_GET["page"])){
$page = $_GET["page"];
}
else {
$page=1;
}
// count all record in this table then divide it on 10 in order to find the last page----- every page has 10 record display
$sql = "SELECT COUNT(*) FROM tt where TTT='$find' ";
$rs_result = mysql_query($sql);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 2);
// this line check that page no must be in integer format
$page = (int)$page;
if ($page > $total_pages) {
$page = $total_pages;
} // if
if ($page < 1) {
$page= 1;
} // if
$start_from = ($page-1) * 2;
$q=mysql_query("select * from tt where TTT='$find' order by ID limit $start_from,2");
$c=mysql_query("select count(*) from tt where TTT='$find'");
echo "<center>".mysql_result($c,0)."Filtered</center>";
echo "<center>";
echo "<table border='2' bgcolor=#CCCCCC>
<tr>
<th>TTT</th>
<th>Enroll Date</th>
<th>Gradution Date</th>
<th>ID</th>
</tr>";
while($row=mysql_fetch_array($q))
{
echo "<tr>";
echo "<td>".$row['TTT']."</td>";
echo "<td>".$row['Enroll_Date']."</td>";
echo "<td>".$row['Graduation_Date']."</td>";
echo "<td>".$row['ID']."</td>";
}
echo "</table>";
echo "<center>";
// paginatio start here
if ($page== 1) {
echo " << < ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> ";
$prevpage = $page-1;
echo " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'><</a> ";
} // if
echo " ( Page [$page] of [$total_pages] ) ";
if ($page == $total_pages) {
echo " > >> ";
} else {
$nextpage = $page+1;
echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>></a> ";
$lastpage=$total_pages;
echo " <a href='{$_SERVER['PHP_SELF']}?page=$lastpage'>>></a> ";
} // if
?>
</div>
</center>
<?php
include("footer.php");
?>
</body>
</html>
You have to pass the filtering criteria along with links to next pages.
echo " <a href='{$_SERVER['PHP_SELF']}?page=1&find=$find'><<</a> ";
and so on with every other link.
<?php
include "includes/connection.php";
//$id=$_REQUEST['category'];
//$catid=mysql_escape_string($id);
$catid = isset($_GET['category']) ? (int)$_GET['category'] : 0;
$recordsPerPage =4;
# 0
// //default startup page
$pageNum = 1;
if(isset($_GET['p']))
{
$pageNum = $_GET['p'];
settype($pageNum, 'integer');
}
$offset = ($pageNum - 1) * $recordsPerPage;
//set the number of columns
$columns = 1;
//set the number of columns
$columns = 1;
$query = "SELECT temp_id, temp_img, temp_header, temp_resize, temp_small, temp_name, temp_type, cat_id, col_id, artist_id FROM `templates` where cat_id = '{$catid}' ORDER BY `temp_id` DESC LIMIT $offset, $recordsPerPage";
$result = mysql_query($query);
//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<div>";
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
while($row = mysql_fetch_array($result)){
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<div class='template'>";
}
echo ...........my data(s).
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
echo "</div>";
}
}
}
echo "</div>";
//}
?>
<div class="pagination">
<?
$query = "SELECT COUNT( temp_id ) AS `temp_date` FROM `templates` where cat_id ='{$catid}'";
$result = mysql_query($query) or die('Mysql Err. 2');
$row = mysql_fetch_assoc($result);
$numrows = $row['temp_date'];
//$numrows = mysql_num_rows($result);
$self = $_SERVER['PHP_SELF'];
$maxPage = ceil($numrows/$recordsPerPage);
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{ if ($page == $pageNum)
{
$nav .= "<span class=\"pegination-selected\">$page</span>";
}
else
{
$nav .= "<aa class=\"pegination\" hreeef=\"javascript:htmlData('$self','p=$page')\">$page</a>";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = "<aa class=\"pagination\" hreeef=\"javascript:htmlData('$self','p=$page')\"><strong><imgee src=\"images/previous.gif\" alt=\"previous\" width=\"5\" height=\"10\" border=\"0\"/></strong></a>";
$first = "<aa class=\"pagination\" hreeef=\"javascript:htmlData('$self','p=1')\"><strong><imgee src=\"images/previous1.gif\" alt=\"first\" width=\"7\" height=\"10\" border=\"0\" /></strong></a>";
}
else
{
$prev = '<strong> </strong>';
$first = '<strong> </strong>';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = "<aa hreeef=\"javascript:htmlData('$self','p=$page')\"> <strong> <imgee src=\"images/next.gif\" alt=\"next\ width=\"5\" height=\"10\" border=\"0\" /></strong></a>";
$last = "<a class=\"pagination\" hreeef=\"javascript:htmlData('$self','p=$maxPage')\"> <strong> <imgee src=\"images/next1.gif\" alt=\"next\" border=\"0\" width=\"7\" height=\"10\" /></strong></a>";
}
else
{
$next = '<strong> </strong>';
$last = '<strong> </strong>';
}
echo "<div class=\"pagination\"> $first $prev <span class=\"pagination-selected\">$nav </span> $next $last </div>";
?>
Here my ajax code:
function GetXmlHttpObject(handler)
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtResult").innerHTML=xmlHttp.responseText
}
else
{
//alert(xmlHttp.status);
}
}
function htmlData(url, qStr)
{
if (url.length==0)
{
document.getElementById("txtResult").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
url=url+"?"+qStr;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true) ;
xmlHttp.send(null);
}
How can I get the selected category id after 1st page in pagination?
Do you pass though category in the request? You haven't given us that information (what is the value of qstr in the javascript?), but I'd guess not.
You're also passing it straight into an SQL query, which leaves you open to injection.
You should use mysql_escape_string() to fix that.
Post it with the AJAX call and return it
Store it in a local JS variable
Add it to the URL
...
You seem to be aware that $_GET['p'] gets the value of the 'p' parameter passed in the querystring. Well $_REQUEST['category'] is doing the same thing. (Technically $_REQUEST checked everything in $_POST, $_GET and $_COOKIE).
So if you haven't set the 'category' in the querystring then it wont contain anything in your code.
You should add ?category=XXX&sid=RAND... to your url
Better use $category = isset($_GET['category']) ? (int)$_GET['category'] : 0;
<?php
include ('database connection file ');
?>
**and this is my index.php**
<?php
if(isset($_GET['page']))
{
$page=$_GET['page'];
$offset=$limit * ($page - 1);
}
else{
$page=1;
$offset=0;
}
if($page==0 || $page > $page_rec){
header('location:index.php?page=1');
}
?>
<body>
<div>
<div class="headingSec"> <h1 align="center">Welcome AdminLogout</h1>
<p align="center">Manage your student database here.</p></div>
<table class="trBgColr">
<thead class="bgColorSec">
<th>Registration Id</th>
<th>Image</th>
<th>Signature</th>
<th>Name</th>
<th>Father's Name</th>
<th>City</th>
<th>Registration Category</th>
<th>Phone Number</th>
<th>Mobile Number</th>
<th>Status</th>
<th>
</thead>
<?php
//$getstudentdetails = "select * from student_details";
$result=mysqli_query($conn,"select * from `student_details` LIMIT $offset,$limit");
/* fetch associative array */
while($row = mysqli_fetch_array($qry)) {
?>
<tr>
<td><?php echo $row["registration_number"]; ?>
<td><?php echo $row["Name"]; ?></td>
<td><?php echo $row["Father_Name"]; ?></td>
<td><?php echo $row["City"]; ?></td>
<td><?php echo $row["Registration_Category"]; ?></td>
<td><?php echo $row["Phone_Number"]; ?></td>
<td><?php echo $row["Mobile_Number"]; ?></td>
<?php if($row['payment_status']==1)
{?>
<td><?php echo "Sucsess"; ?></td>
<?php
}
else{
?>
<td><?php echo "Failed"; ?></td>
<?php
}?>
<?php
}
$pre=$page - 1;
$next=$page + 1;
?>
</tr>
</table>
</div>
<br />
<br />
<div class="pagination">
<?php
for($i=1;$i<=$page_rec;$i++){
continue;
?>
<?php $i;?>
<?php } ?>
Previous«
Next»