simple php pagination script:
'<'?php
$pageNum=1;
$rowsPerPage=10;
if(isset($_REQUEST['p']))
{
$pageNum = $_REQUEST['p'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$npage=$pageNum+1;
$prev=$pageNum-1;
$sql="SELECT oid,empid,empname,name,mdate,starttime,closetime,duration,status FROM rept join emp where rept.empid=emp.emp_id and emp.man_id='$manid' order by oid desc limit $offset,$rowsPerPage";
$rlts=mysql_query($sql);
while($row=mysql_fetch_array($rlts))
{
$cid = $row['oid'];
$emp_id = $row['empid'];
$empnm = $row['empname'];
$name= $row['name'];
$mod_date = $row['mdate'];
$start_time = $row['starttime'];
$start = date("g:i a", strtotime(".$starttime."));
$close_time = $row['close_time'];
$close = date("g:i a", strtotime(".$closetime."));
$duration = $row['duration'];
$status = $row['status'];
if($status==p)
{
$status='On process';
}
elseif($status==f)
{
$status='Finished';
}
else
{
$status='Hold';
}
$query = mysql_query("select count(*) as numrows from rept join emp where rept.empid=emp.empid and emp.man_id='$manid' order by oid desc") or die (mysql_error($query));
$result = mysql_fetch_object($query);
$numrows = $result->numrows;
$maxPage = ceil($numrows/$rowsPerPage);
$nav = '';
for($page = $pageNum; $page '<'= $pageNum+5; $page++)
{
if ($page '<'= $maxPage)
{
if ($page == $pageNum)
{
if($page !=1)
{
$nav .= "$page"; // no need to create a link to current page
}
}
else
{
$nav .= "'<'a href='typereport.php?p=$page'>'<'font color='#000000'>".$page."'<'/font>'<'/a>";
}
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " '<'a href='typereport.php?p=$page'>'<'font color='#000000'>'<''<'/font>'<'/a>";
$first = " '<'a href='typereport.php?p=1'>'<'font color='#000000'><<'<'/font>'<'/a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum '< '$maxPage)
{
$page = $pageNum + 1;
$next = " '<'a href='typereport.php?p=$page'>'<'font color='#000000'>>'<'/font>'<'/a> ";
$last = " '<'a href='typereport.php?p=$maxPage'>'<'font color='#000000'>>>'<'/font>'<'/a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
?>
'<'tr>'<'td>'<'?php echo $emp_id; ?>'<'/td>'<'td >'<'?php echo ucfirst($coral_empnm); ?>'<'/td>'<'td >'<'?php echo $book_name; ?>'<'/td>'<'td >'<'?php echo $pages; ?>'<'/td>'<'td >'<'a href="#" onclick="popupView('<'?php echo $cid; ?>)">view'<'/a>'<'/td>'<'td >'<'?php if($work_status!=p) { ?>'<'a href="textdown.php?download_file='<'?php echo $book.'_'.$cid; ?>.txt">Download'<'/a>'<'?php } else { echo '-'; } ?>'<'/td>'<'td >'<'?php echo $assign_date; ?>'<'/td>'<'td >'<'?php echo $type_duration; ?>'<'/td>'<'td>'<'?php echo $status; ?>'<'/td>'<'/tr>
'<'?php
}
?>
'<'/table>
'<'div>'<'?php echo $first.$prev.$nav.$next.$last; ?>'<'/div>
No comments:
Post a Comment