I just started to learn PHP this week, and I'd search for possible solution on this but I can make it right. While I sucessfully created a pagination that sorts queries into alphabetical order, I wasn't successful in creating a numerical pagination, in which it will limit the number of queries to be displayed. Also, I wasn't able to combined these two types of pagination with two different queries, one for A-Z sorting, and one for the number of queries to be displayed in a single page.
Here's my code
`<?php
include 'includes/connection.php';
$character = '';
$characters = '';
if (isset($_GET['character']))
{
$character = $_GET['character'];
$character = preg_replace('#[^a-z]#i', '', $character);
$sql = "SELECT * FROM drivers_info WHERE last_name LIKE '$character%' ORDER BY last_name";
}
else{
$sql = "SELECT * FROM drivers_info ORDER BY rfid ";
$pageno = 1
}
$result = mysqli_query($db, $sql);
<body>
<br /><br />
<br /> <br />
Here's the code to create an alphabetical pagination
<div class="table-responsive">
<div align="center">
<?php
$character = range('A', 'Z');
echo '<ul class="pagination">';
foreach($character as $alphabet)
{
echo '<li>'.$alphabet.'</li>';
}
echo '</ul>';
?>
</div>
<?php
Here's the code for displaying the queries alphabetically
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $row["rfid"]; ?></td>
<td><?php echo $row["last_name"]; ?></td>
<td><?php echo $row["first_name"]; ?></td>
<td><?php echo $row["middle_name"]; ?></td>
<td><?php echo $row["gender"]; ?></td>
<td><?php echo $row["age"]; ?></td>
<td><?php echo $row["height"]; ?></td>
<td><?php echo $row["weight"]; ?></td>
<td><?php echo $row["address"]; ?></td>
<td><?php echo $row["contact_no"]; ?></td>
<td><?php echo $row["license_type"]; ?></td>
<td><?php echo $row["license_no"]; ?></td>
<td><?php echo $row["expiration"]; ?></td>
<td><?php echo $row["nationality"]; ?></td>
<td><?php echo $row["eyes_color"]; ?></td>
<td><?php echo $row["blood_type"]; ?></td>
</tr>
<?php
}
}
</body>
If you had any code or idea on it, would you mind sharing it with me? Thank you so much, I needed this to accomplish my school project.
`
Here is best reference code for understanding pagination logic
<?php
$host = "localhost";
$user = "root";
$pass = "New";
$db = "booksgood";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// how many rows to show per page
$rowsPerPage = 10;
// by default we show first page
$page_num = 1;
// if $_GET['page'] defined, use it as page number, $_GET gets the page number out of the url
//set by the $page_pagination below
if(isset($_GET['page'])){$page_num = $_GET['page'];}
//the point to start for the limit query
$offset = $page_num;
// Zero is an incorrect page, so switch the zero with 1, mainly because it will cause an error with the SQL
if($page_num == 0) {$page_num = 1;}
// counting the offset
$sql = "SELECT * FROM bookdata where titles like 's%' order by titles LIMIT $offset, $rowsPerPage ";
$res = mysql_query($sql) or die(mysql_error());
// how many rows we have in database
$sql2 = "SELECT COUNT(id) AS numrows FROM bookdata where titles like 's%'";
$res2 = mysql_query($sql2) or die(mysql_error());
$row2 = mysql_fetch_array($res2);
$numrows = $row2['numrows'];
// print the random numbers
while($row = mysql_fetch_array($res))
{
//Echo out your table contents here.
echo $row[1].'<BR>';
echo $row[2].'<BR>';
echo '<BR>';
}
// how many pages we have when using paging?
$numofpages = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = "/paging3.php?";
if ($numofpages > '1' ) {
$range =15; //set this to what ever range you want to show in the pagination link
$range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
$range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
$page_min = $page_num- $range_min;
$page_max = $page_num+ $range_max;
$page_min = ($page_min < 1) ? 1 : $page_min;
$page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
if ($page_max > $numofpages) {
$page_min = ($page_min > 1) ? $numofpages - $range + 1 : 1;
$page_max = $numofpages;
}
$page_min = ($page_min < 1) ? 1 : $page_min;
//$page_content .= '<p class="menuPage">';
if ( ($page_num > ($range - $range_min)) && ($numofpages > $range) ) {
$page_pagination .= '<a class="num" title="First" href="'.$self.'page=1"><</a> ';
}
if ($page_num != 1) {
$page_pagination .= '<a class="num" href="'.$self.'page='.($page_num-1). '">Previous</a> ';
}
for ($i = $page_min;$i <= $page_max;$i++) {
if ($i == $page_num)
$page_pagination .= '<span class="num"><strong>' . $i . '</strong></span> ';
else
$page_pagination.= '<a class="num" href="'.$self.'page='.$i. '">'.$i.'</a> ';
}
if ($page_num < $numofpages) {
$page_pagination.= ' <a class="num" href="'.$self.'page='.($page_num + 1) . '">Next</a>';
}
if (($page_num< ($numofpages - $range_max)) && ($numofpages > $range)) {
$page_pagination .= ' <a class="num" title="Last" href="'.$self.'page='.$numofpages. '">></a> ';
}
//$page['PAGINATION'] ='<p id="pagination">'.$page_pagination.'</p>';
}//end if more than 1 page
echo $page_pagination.'<BR><BR>';
echo 'Number of results - '.$numrows ;
echo ' and Number of pages - '.$numofpages.'<BR><BR>';
// Free resultset
mysql_free_result($res);
// and close the database connection
mysql_close($con);
?>
here is reference code link
I want to display five record per page through pagination (mysql,php,html,css) until all the records are displayed, navigation to pages must be like, Page: 1 2 3 4 5 6 7 7 8... Last.
HERE IS MY CODE TO VIEW ALL THE RECORDS FROM emp_master table.
I am new to PHP so please write an easily understandable code for pagination. I have seen few examples but they are not working.
<?php
$con=mysqli_connect("localhost","user","password","dataplus");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM emp_master");
echo "<table border='1'>";
$i = 0;
while($row = $result->fetch_assoc())
{
if ($i == 0) {
$i++;
echo "<tr>";
foreach ($row as $key => $value) {
echo "<th>" . $key . "</th>";
}
echo "</tr>";
}
echo "<tr>";
foreach ($row as $value) {
echo "<td>" . $value . "</td>";
}
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
I want to display five record per page through pagination untill all the records are displayed, navigation to pages must be like, Page: 1 2 3 4 5 6 7 7 8... Last.
This code below is not working:
$dbhost="localhost";
$dbuser="10053";
$dbpass="n6867242";
$database="0368";
$rec_limit = 10;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('1005368');
/* Get total number of records */
$sql = "SELECT count(emp_id) FROM emp_master ";
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) ) {
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}else {
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT emp_id, emp_name, e_mail ".
"FROM emp_master ".
"LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "EMP ID :{$row['emp_id']} <br> ".
"EMP NAME : {$row['emp_name']} <br> ".
"EMP MAIL : {$row['e_mail']} <br> ".
"--------------------------------<br>";
}
if( $page > 0 ) {
$last = $page - 2;
echo "Last 10 Records |";
echo "Next 10 Records";
}else if( $page == 0 ) {
echo "Next 10 Records";
}else if( $left_rec < $rec_limit ) {
$last = $page - 2;
echo "Last 10 Records";
}
mysql_close($conn);
If you want just PHP MySQL code, I usually use something like the following.
$page=max(intval($_GET['page']),1); // assuming there is a parameter 'page'
$itemsperpage = 5;
$total=100; // total results if you know it already otherwise use another query
$totalpages = max(ceil($total/$itemsperpage),1);
$query = "SELECT * FROM emp_master LIMIT ".(($page-1)*$itemsperpage).",".$itemsperpage; // this will return 5 items based on the page
You can use a library called dataTables that will auto paginate the data and you can easily customize it to suit your needs with the look and how many records to show per page. It also has a search field which enables users to search your data without any extra code.
All you have to do is include a couple of cdn's and the following code and everything works fine
$(document).ready(function(){
$('#myTable').DataTable();
});
Some examples here
you just should remove spaces in href and also make $page = $page + 1 when page is 0
if( $page > 0 ) {
$last = $page - 2;
echo "Last 10 Records |";
echo "Next 10 Records";
}else if( $page == 0 ) {
$page = $page + 1;
echo "Next 10 Records";
}else if( $left_rec < $rec_limit ) {
$last = $page - 2;
echo "Last 10 Records";
}
Link is here for demo, click here to experience the result
Here is the code working for me, just change your db name, username and password
and get pagination done. You can change $rec_limit value to your desired no. of records per page.
<?php
$host="localhost";
$username="68";
$password="67242";
$database="68";
$rec_limit = 5;
$conn = mysql_connect($localhost,$username,$password);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('10');
/* Get total number of records */
$sql = "SELECT count(emp_id) FROM emp_master ";
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) ) {
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}else {
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT eid,ename, email, quali, gender, contactno, birthdate, joiningdate,CURDATE(), TIMESTAMPDIFF( YEAR, birthdate, CURDATE( ) ) AS age ".
"FROM emp_master ".
"LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
echo "<table border='1'>";
$i = 0;
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
if ($i == 0) {
$i++;
echo "<tr>";
foreach ($row as $key => $value) {
echo "<th>" . $key . "</th>";
}
echo "</tr>";
}
echo "<tr>";
foreach ($row as $value) {
echo "<td>" . $value . "</td>";
}
echo "</tr>";
}
echo "</table>";
if( $page > 0 ) {
$last = $page - 2;
echo "Last 5 Records | ";
echo "Next 5 Records";
}else if( $page == 0 ) {
$page = $page + 0;
echo "Next 5 Records";
}else if( $left_rec < $rec_limit ) {
$last = $page - 2;
echo "Last 5 Records";
}
mysql_close($conn);
php?>
IF your are using mysqli the code is below
$conn=mysqli_connect("localhost","root","","ui");
$start=0;
$limit=5;
$t=mysqli_query($conn,"select * from form_table");
$total=mysqli_num_rows($t);
if(isset($_GET['id']))
{
$id=$_GET['id'] ;
$start=($id-1)*$limit;
}
else
{
$id=1;
}
$page=ceil($total/$limit);
$query=mysqli_query($conn,"select * from form_table limit $start, $limit");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script s src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
</head>
<body>
<div class="container">
<h2>Table</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gender</th>
<th>Hobbies</th>
<th>Course</th>
</tr>
</thead>
<tbody>
<?php
while($ft=mysqli_fetch_array($query))
{?>
<tr>
<td><?= $ft['0']?></td>
<td><?= $ft['1']?></td>
<td><?= $ft['2']?></td>
<td><?= $ft['3']?></td>
<td><?= $ft['4']?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<ul class="pagination">
<?php if($id > 1) {?> <li>Previous</li><?php }?>
<?php
for($i=1;$i <= $page;$i++){
?>
<li><?php echo $i;?></li>
<?php
}
?>
<?php if($id!=$page)
{?>
i Give you an example of my project of pagination. Just you have to put your values in the code
$sql="SELECT * FROM tblname LIMIT $next,5";
$results = mysqli_query($conn,$sql);
}
else if (isset($_POST['prev']))
{
$prev1=$_POST['prev'];
$next=$_POST['prev'];
$prev=$prev1;
$sql="SELECT * FROM tablename LIMIT $prev,5";
$prev=$prev1;
$results = mysqli_query($conn,"SELECT * FROM tablename LIMIT $prev,10");
if($prev==0)
{
$prev = 0;
}
else
{
$prev=$next-10;
}
}
else
{
$next=0;
$prev=0;
$results = mysqli_query($conn,"SELECT * FROM tablename LIMIT $next,10");
}
I got it to order by but now the paginaging doesn't work. NOTHING prints into my error_logs now.
User Red Acid helpedme out with the the missing Whitespace and use a string variable instead of PHP_SELF.
Once I press next record I get:
Not Found
The requested URL /surf/$index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
My code:
<?php
$dbHost = "localhost";
$dbUser = "";
$dbPass = "";
$dbName = "";
$tbl_name="";
$rec_limit = 20;
$order = "ORDER BY";
$scriptname = 'index.php';
mysql_connect("$dbHost", "$dbUser", "$dbPass")or die("cannot connect");
mysql_select_db("$dbName")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name $order ".$_GET["orderby"]." ".$_GET["desc"];
$result=mysql_query($sql);
$sql = "SELECT count(steamid) FROM $tbl_name";
$result= mysql_query($sql);
if(! $result)
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($result, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT * ".
"FROM $tbl_name ".
"$order points DESC ".
"LIMIT $offset, $rec_limit";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['points']; ?></td>
<td><?php echo $rows['winratio']; ?></td>
<td><?php echo $rows['pointsratio']; ?></td>
<td><?php echo $rows['finishedmaps']; ?></td>
<td><?php echo $rows['lastseen']; ?></td>
</tr>
</tr>
<?php
}
if( $page > 0 )
{
$last = $page - 2;
echo "Last 10 Records |";
echo "Next 10 Records";
}
else if( $page == 0 )
{
echo "Next 10 Records";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "Last 10 Records";
}
mysql_close();
?><?php
$dbHost = "localhost";
$dbUser = "c1226125_ms";
$dbPass = "wR(#ucrb5oG.";
$dbName = "c1226125_timer";
$tbl_name="ck_playerrank";
$rec_limit = 20;
$order = "ORDER BY";
$scriptname = 'index.php';
mysql_connect("$dbHost", "$dbUser", "$dbPass")or die("cannot connect");
mysql_select_db("$dbName")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name $order ".$_GET["orderby"]." ".$_GET["desc"];
$result=mysql_query($sql);
$sql = "SELECT count(steamid) FROM $tbl_name";
$result= mysql_query($sql);
if(! $result)
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($result, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT * ".
"FROM $tbl_name ".
"$order points DESC ".
"LIMIT $offset, $rec_limit";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['points']; ?></td>
<td><?php echo $rows['winratio']; ?></td>
<td><?php echo $rows['pointsratio']; ?></td>
<td><?php echo $rows['finishedmaps']; ?></td>
<td><?php echo $rows['lastseen']; ?></td>
</tr>
</tr>
<?php
}
if( $page > 0 )
{
$last = $page - 2;
echo "Last 10 Records |";
echo "Next 10 Records";
}
else if( $page == 0 )
{
echo "Next 10 Records";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "Last 10 Records";
}
mysql_close();
?>
problem that you dont have white space between ORDER BY and DESC:
$sql="SELECT * FROM $tbl_name ORDER BY ".$_GET["orderby"].$_GET["desc"];
should be:
$sql="SELECT * FROM $tbl_name ORDER BY ".$_GET["orderby"]." ".$_GET["desc"];
use string variable instead of PHP_SELF:
$scriptname = 'myscript.php'; // OR http://domain.com/myscript.php
echo "Last 10 Records";
my default load page is ok with next and prev results.. but for search results i can get only first page then blank for the next page. let say total search results row is 9, it display 3 pages with next link. but when i click the next link, it queries no result on the page 2. here is my code:
echo '<table><tr><td>';
echo '<form method="post" name="frmSearch" action="mypage.php>
Search by name
<input type="text" name="txtSearch">
<input type="submit" name="submit" value="Search">
</form>';
$per_page = 5;
$page = 1;
if (isset($_GET['page']))
{
$page = intval($_GET['page']);
if($page < 1) $page = 1;
}
$start_from = ($page - 1) * $per_page;
$Prev_Page = $page - 1;
$Next_Page = $page + 1;
if (!$_POST){
//$sql = "SELECT * FROM mytable LIMIT $start_from, $per_page";
//$totalr = mysql_query("SELECT COUNT(*) FROM mytable");
//$totalr = mysql_fetch_row($totalr);
//$totalr = $totalr[0];
//$total_pages = $totalr / $per_page;
//$total_pages = ceil($total_pages);
//$listresult = mysql_query($sql);
//$total = mysql_num_rows($listresult);
}
else {
if ($_POST['txtSearch']!="") {$cond1 = " name LIKE
'%".$_POST['txtSearch']."%' ";} else {$cond1 = 1; }
$sql = "SELECT * FROM mytable WHERE ".$cond1." LIMIT $start_from, $per_page";
$totalr = mysql_query("SELECT COUNT(*) FROM mytable WHERE name LIKE
'%".$_POST['txtSearch']."%' ");
$totalr = mysql_fetch_row($totalr);
$totalr = $totalr[0];
$total_pages = $totalr / $per_page;
$total_pages = ceil($total_pages);
$listresult = mysql_query($sql);
$total = mysql_num_rows($listresult);
}
if($total == 0){
echo "<center>No records found.</center>";
}
echo "<span style='float:right;margin-top:8px;'>[ <a href='new.php'>Add New</a>
]</span></td></tr>";
echo "<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
";
while ($_POST = mysql_fetch_assoc($listresult)){
echo "<tr>";
echo "<td>" . $_POST['id'] . "</td>";
echo "<td>" . $_POST['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</table>";
echo $totalr." result";
echo "<br>";
if ($Prev_Page) {
echo " <a href ='{$_SERVER['PHP_SELF']}?page=$Prev_Page'><< Prev</a> ";
}
if ($totalr > $per_page) {
for($i = 1; $i <= $total_pages; ++$i)
{
echo "<a href='{$_SERVER['PHP_SELF']}?page=$i'>$i</a> | ";
}
}
if ($page!=$total_pages) {
echo " <a href='{$_SERVER['PHP_SELF']}?page=$Next_Page'>Next >></a> ";
}
maybe you need to use SELECT COUNT(*) FROM mytable WHERE name LIKE '%$search%' ... remember to escape the $_POST['txtSearch']
I have a script with the code below and a pagination where the user can check checkboxes to narrow doen the results shown everything seems to work great the only problem is that when a user clicks the next page in the pagination the results are lost and the default results are shown. I think I may need to use sessions to store the query or statement but I am unsure how to use them. If anyone can help me or point me in the right direction I would be very greatful.
<?php
include("config.php");
$start = 0;
$per_page = 10;
if(!isset($_GET['page'])){
$page = 1;
} else
{
$page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;
$sql="select id,question,correctAnswer,category from math order by id";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = $num_rows / $per_page;
$sql .= " LIMIT $start, $per_page";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{ ?>
..............
<?php
if($page > 1){
$prev = $page - 1;
$prev = " <a href='?page=$prev'>prev</a> ";
} else {
$prev = "";
}
if($page < $num_pages){
$next = $page + 1;
$next = " <a href='?page=$next'>next</a> ";
}
else
{
$next = "";
}
echo $prev;
echo $next;
?>
and the following code is about selection of checkbox value one by one and all
function selectall()
{
var selectAll = document.forms[0].length;
if(document.forms[0].topcheckbox.checked==true)
{
for(i=1;i<selectAll;i++)
{
document.forms[0].elements[i].checked=true;
}
}
else
{
for(i=1;i<selectAll;i++)
document.forms[0].elements[i].checked=false;
}
}
function goSelect()
{
var select = document.forms[0].length;
var checkboxes=""
for(i=1;i<select;i++)
{
if(document.forms[0].elements[i].checked==true)
checkboxes+= " " + document.forms[0].elements[i].name
}
if(checkboxes.length>0)
{
var con=confirm("You have selected ...........");
if(con)
{
window.location.assign("submit.php?recsno="+checkboxes)
// document.forms[0].submit()
}
}
else
{
alert("No record is selected.")
}
}
You could probably use the PHP Get method? and then receive it in your javascript.
For example; searchurl.com/results.php?box=1
Then retrieve it on the next page.
I believe this should help you, be sure to let me know if you need more detail.
This is my all code.
include("config.php");
$start = 0;
$per_page = 10;
if(!isset($_GET['page'])){
$page = 1;
} else{
$page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;
$sql="select id,question,correctAnswer,category from math order by id";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = $num_rows / $per_page;
$sql .= " LIMIT $start, $per_page";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{ ?>
<tr>
<td><input name="<?php echo $row['id']; ?>" type="checkbox" class="check"></td>
<td><center><?php echo htmlspecialchars_decode($row['id'], ENT_QUOTES); ?></center></td>
<td style="padding-left:25px;margin:15px"><?php echo $_SESSION['question']= htmlspecialchars_decode($row['question'], ENT_QUOTES); ?></center></td>
<td><center><?php echo htmlspecialchars_decode($row['correctAnswer'], ENT_QUOTES); ?></center></td>
<td><center><?php echo htmlspecialchars_decode($row['category'], ENT_QUOTES); ?></center></td>
<td>View</td>
</tr>
<?php } ?>
<tr>
<td><strong>Select</strong></td>
<td><strong>Sr No </strong></td>
<td><strong>Question </strong></td>
<td><strong>CorrectAnswer </strong></td>
<td><strong>Category </strong></td>
<td><strong>View Details</strong></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
if($page > 1){
$prev = $page - 1;
$prev = " <a href='?page=$prev'>prev</a> ";
} else {
$prev = "";
}
if($page < $num_pages){
$next = $page + 1;
$next = " <a href='?page=$next'>next</a> ";
}
else
{
$next = "";
}
echo $prev;
echo $next;
?>