Need help changing msql_results to an equivalent of PDO instead - php

I am having an issue trying to figure how to replace mssql_result so that this code can work for mssql not MySQL. I have tried different ways still little lost on what to do. If anyone has any examples on how to do this would be big help. I will continue to try figuring it out and then post answer if I find it.
<html>
<head>
<title></title>
</head>
<body>
<?php
$serverName = "localhost";
$objConnect = new PDO( "sqlsrv:server=$serverName ; Database=maintenance", "test", "test123") or die("Error Connect to Database");
$strSQL = $objConnect->prepare("SELECT * FROM requests WHERE status='Received' ORDER BY id DESC");
$strSQL->execute();
$Num_Rows = $strSQL->fetchColumn();
$Per_Page = 2; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Lan ID </div></th>
<th width="98"> <div align="center">Name </div></th>
</tr>
<?php
for($i=$Page_Start;$i<$Page_End;$i++)
{
?>
<tr>
<td><div align="center"><?php echo mssql_result($objQuery,$i,"lanId");?></div></td>
<td><?php echo mssql_result($objQuery,$i,"name");?></td>
<?php
}
?>
</table>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
?>
</body>
</html>

<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ID </div></th>
<th width="91"> <div align="center">Lan ID </div></th>
<th width="98"> <div align="center">Name </div></th>
</tr>
<?php
while($result = $strSQL->fetch( PDO::FETCH_ASSOC ))
{
?>
<tr>
<td><div align="center"><?php echo $result["lanId"];?></div></td>
<td><?php echo $result["name"];?></td>
<?php
}
?>
</table>

Related

PHP MSSQL Pagination doesn't go to the next page

<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?php
$sql_name = 'test';
$sql_user = 'sa';
$sql_pass = '';
$dbConn = odbc_connect("Driver={SQL Server};Server={$sql_name};",$sql_user,$sql_pass) or die('Database Connection Error!');
if (!$dbConn) {
exit("Connection failed:".odbc_errormsg());
}
$strSQL = "SELECT * FROM test_db.dbo.test ORDER BY ID ASC ";
$objExec = odbc_exec($dbConn, $strSQL) or die ("Error Execute [".$strSQL."]");
$Num_Rows = 0;
while(odbc_fetch_row($objExec))$Num_Rows++; // Count Record
$Per_Page = 22; // Per Page
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page)+1;
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
if($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ID </div></th>
<th width="98"> <div align="center">Name </div></th>
</tr>
<?php
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$objResult = odbc_fetch_array($objExec,$i);
?>
<tr>
<td><div align="center"><?=$objResult["ID"];?></div></td>
<td><?=$objResult["Name"];?></td>
</tr>
<?php
}
?>
</table>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
odbc_close($dbConn);
?>
</body>
</html>
When I press the button to go to the next page or any other page number it stays on the same page but if I change $Page=2; It will go to page 2 and when pressed to go to another page, it will stay at the same page.

nested if else syntax error php [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
it says syntax error t_else, what could be the problem?
it really is making me crazy for finding what did i do wrong in this code
what could be myy mistake here?
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
$query1 = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php
}
}
else{
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_status='Active' limit $page1,5";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300"
width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
?>
<?php
$query1 = "select * from tbl_news where news_status='Active'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php # code...
}
}
?>
here is the full code, of what errror gives me, please help me guys it takes me a a lot of time having this kind of problem i already tried everything i could but maybe you guys could me solve my problem hahahaha it really drained my mind here , im already mindblown on what is the my currently facing problem
You are missing < at the a tag inside the first while loop (exactly on line 21 when I copy/paste your code). That might be the reason it doesn't recognize the else statement, because it can't get to it properly.
try this code. may be it resolve your problem.
I have corrected some syntax mistake in your code.
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php
}
}else{
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_status='Active' limit $page1,5";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_status='Active'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php # code...
}
}
?>

Data is printing multiple time in php?

The course name php is available in the table one time but when I retrieve it from table it printing multiple time. I have tried the following code - please help me what's wrong with the code? (if I remove the drop down which is available below the heading it is printing single time in the table)
<?php
include("session.php");
?>
<?php
include("../view/common/head.php");
?>
<?php
include('../view/common/tab.php');
?>
<body class="bg-color">
<div class="container">
<h1> List Of Courses</h1>
<br/>
<?php
if (isset($_SESSION['message1']))
{
echo $_SESSION['message1'];
unset($_SESSION['message1']);
}
?>
<?php
if (isset($_SESSION['courseupdated']))
{
echo $_SESSION['courseupdated'];
unset($_SESSION['courseupdated']);
}
?>
<?php
if (isset($_SESSION['deletecourse']))
{
echo $_SESSION['deletecourse'];
unset($_SESSION['deletecourse']);
}
?>
<?php
if (isset($_SESSION['notdelete']))
{
echo $_SESSION['notdelete'];
unset($_SESSION['notdelete']);
}
?> <div class="col-md-6 form-group">
<select class="form-control">
<?php
include('../model/functions.php');
$table="courses";
$condition="";
$drop=Selectdata($table,$condition);
foreach($selectarray as $drop)
{
echo '<option value="'.$drop['course_id'].'">'.$drop['course_name'].'</option>';
}
?>
</select>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>Sno</th>
<th>Course Name</th>
<th>Course Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$per_page=5;
if (isset($_GET['page'])) {
$page = $_GET['page'];
}
else {
$page=1;
}
$table="courses";
$per_page=5;
$start_from = ($page-1) * $per_page;
$condition="limit ".$start_from.",".$per_page." ";
$limit=Selectdata($table,$condition);
if($rowcount==0)
{
echo "no records found";
}
else
{
$sno=($page-1) * $per_page;
foreach($selectarray as $course){
$sno++;
echo '<tr>';
echo '<td>'.$sno.'</td>';
echo '<td>'.$course['course_name'].'</td>';
echo '<td>'.$course['course_description'].'</td>';
echo '<td><button type="submit">edit</button><button Onclick="return ConfirmDelete();" type="submit">Delete</button></td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
Click here to add new course
<br/>
<br/>
Toggle Menu
</div>
<?php
$table = "courses";
$condition=" ";
$select=Selectdata($table,$condition);
$total_records = $rowcount;
$total_pages = ceil($total_records / $per_page);
echo '<div class="text-center">';
echo '<ul class="pagination">';
echo "<li><a href='courselist.php?page=1'>".'<<'.'</a></li>';
for ($i=1; $i<=$total_pages; $i++) {
echo "<li><a href='courselist.php?page=".$i."'>".$i.'</a></li>';
}
echo "<li><a href='courselist.php?page=$total_pages'>".'>>'.'</a></li>';
echo "</ul>";
echo '</div>';
?>
<?php
include("../view/common/footer.php");
?>
functions.php
function Selectdata($table,$condition="")
{
global $conn,$result,$selectarray,$rowcount;
$sql="SELECT * from ".$table." ".$condition." ";
$result=$conn->query($sql);
$rowcount=$result->num_rows;
while($row=$result->fetch_assoc())
{
$selectarray[]=$row;
}
return $result;
}
I hope this code is not intended to be used in a real project.
Just add
$selectarray = array();
before
while
in Selectdata function definition.
What happens is that each time you call that function it just amends the full rowset to the same array as it is global.
Try this :
foreach($selectarray as $row)
{
echo '<option value="'.$row['course_id'].'">'.$row['course_name'].'</option>';
}

How do i generate more than 1 pdfs on click of a button

I am creating a component for teachers where in teacher can generate pdf for all the students who have completed the course.
Checking all the students and pdfs should be generated and saved on disk. After which a download link is provided to download the zip of all the pdfs generated. This is what i want to achieve. I am using fpdf for generating pdf.
Any suggestions ?
Below is the form that is posted and students id-
<form
action="<?php echo JRoute::_('index.php?option=com_mentor&view=download_certificate&cid=' . $cid . '&Itemid=529') ?>"
name="download_certificate" method="post" id="download_certificate">
<table class="adminlist" border="1" cellpadding="0" cellspacing="0"
style="table-layout: fixed" id="content">
<thead>
<tr>
<th class="nowrap" style="width: 35px">
<input type="checkbox" name="selectall" id="selectall">
</th>
<th class="nowrap" align="center">
<?php echo JText::_('COM_MENTOR_USER_NAME'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_COURSE_STATUS'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ENROLLMENT_DATE'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ACTIVITY'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_SCORE'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_RESULT'); ?>
</th>
</tr>
</thead>
<tbody>
<?php
//echo '<pre>';print_r($this->mentor_details); die;
foreach ($this->mentor_details as $students) {
$cid = $this->mentor_details['cid'];
$i = 1;
foreach ($students['students'] as $student) {
$userid = $student['id'];
// echo '<pre>';
// print_r($student);
// die;
?>
<tr class="status" id="<?php echo $userid ?>">
<td align="center">
<input type="checkbox" id="<?php echo $userid ?>" name="check[]" class="checkbox1"
value="<?php echo $userid ?>">
</td>
<td>
<a href="<?php echo JRoute::_('index.php?option=com_mentor&view=grader&cid=' . $cid . '&uid='
. $userid . $itemid) ?>">
<?php echo $student['username']; ?>
</a>
</td>
<!-- <td>
<?php// echo $student['email']; ?>
</td> -->
<td align="center">
<?php
$incomplete = $completed = $not_started = 0;
for ($k = 0; $k < count($student['elements']); $k++) {
foreach ($student['elements'] as $elements) {
if ($elements['userid'] == $userid) {
// echo '<pre>';print_r($elements); die;
if ($elements['element']['cmi.core.lesson_status'] == 'incomplete') {
$incomplete++;
} else {
$completed++;
}
}
}
}
if ($incomplete == 0 && $completed == 0) {
echo 'Not yet started';
} else {
if ($completed == count($student['elements'])) {
echo 'Completed';
} else {
echo 'Incomplete';
}
}
?>
</td>
<td align="center">
<?php
if (!empty($student['timestart'])) {
$date = date('d-m-Y H:i', $student['timestart']);
echo $date;
} else {
echo "Not yet started";
} ?>
</td>
<td align="center">
<?php
if (!empty($student['activity']['lasttime']) && (!empty($student['activity']['starttime']))) {
$start_date = date('d-m-Y H:i', $student['activity']['starttime']);
$last_date = date('d-m-Y H:i', $student['activity']['lasttime']);
echo $start_date . '<br/>' . $last_date;
} else {
echo "-";
} ?>
</td>
<td align="center">
<?php
$grades = $student['grades'];
$total_grade = array();
$j = 0;
//for ($j = 0; $j < count($grades); $j++) {
// $total_grade[$j] = $grades[$j]['finalgrade'];
//}
//print_r($total_grade);die;
if (!empty($grades)) {
//echo number_format(array_sum($total_grade), 2);
$total_grade[$j] = $grades[$j]['finalgrade'];
echo number_format($total_grade[$j], 2);
} else {
echo '-';
}
//echo '<pre>';
//print_r($student['grades']);
//die;
?>
</td>
<td align="center">
<?php
//echo '<pre>';print_r($student);die;
if (!empty($student['scores'])) {
if (isset($grades[$j]['feedbacktext'])) {
echo $grades[$j]['feedbacktext'];
} else {
echo '-';
}
} else {
echo '-';
}
?>
</td>
</tr>
<?php $i++;
}
} ?>
</tbody>
</table>
</form>
<script>
function checked_value() {
var checkedValue = [];
var $len = $(".checkbox1:checked").length;
if ($len == 0) {
alert('Please select user');
}
// else if ($len > 1) {
// alert('Please select a single user only.');
// }
else {
$(".checkbox1").each(function () {
var $this = $(this);
if ($this.is(":checked")) {
checkedValue.push($this.attr("id"));
}
});
$("#download_certificate").submit();
</script>
On Clicking image tag, form is submitted with the students id and I am getting students data, his name, grades, course,
<img src="/components/com_mentor/images/certificate_blue.png" class="certificate-ico right"
title="Download Certificate" onclick="checked_value();"/>
After this processing, page is redirected to pdf.php page
require_once('/wamp/opt/bitnami/apache2/htdocs/lms/lib/fpdf/fpdf.php');
$pdf = new FPDF(); $pdf->SetFont('times', '', 12);
$pdf->SetTextColor(50, 60, 100); $pdf->AddPage('L');
$pdf->SetDisplayMode(real, 'default'); $pdf->SetXY(10, 60);
$pdf->SetFontSize(12);
$pdf->Write(5, 'Dear Ms.XYX');
$filename = "test.pdf";
$dir = "/assets/";
$pdf->Output($dir . $filename, 'F');
Thanks guys for your help.. Solved my question.
Looped through the pdf function for n no. of users.

Displaying number of records in continuous fashion in php paging

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 "&nbsp&nbsp";
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.

Categories