<?php
include("include/db.inc.php");
$sql = mysql_query("SELECT * FROM emp");
$nr = mysql_num_rows($sql);
if(isset($_GET['page'])){
$pn = preg_replace('#[^0-9]#i','',$_GET['page']);
}else{
$pn = 1;
}
$itemPerPage = 10;
$lastPage = ceil($nr/$itemPerPage);
if($pn < 1){
$pn = 1;
}elseif($pn > $lastPage){
$pn = $lastPage;
}
$centerPage = '';
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if($pn == 1){
$centerPage .= ' <span class="pagNumActive">'. $pn .'</span> ';
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $add1 .'">'. $add1 .'</a> ';
}elseif($pn == $lastPage){
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $sub1 .'">'. $sub1 .'</a> ';
$centerPage .= ' <span class="pagNumActive">'. $pn .'</span> ';
}elseif($pn == 2 && $pn < ($lastPage - 1)){
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $sub2 .'">'. $sub2 .'</a> ';
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $sub1 .'">'. $sub1 .'</a> ';
$centerPage .= ' <span class="pagNumActive">'. $pn .'</span> ';
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $add1 .'">'. $add1 .'</a> ';
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $add2 .'">'. $add2 .'</a> ';
}elseif($pn > 1 && $pn < $lastPage){
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $sub1 .'">'. $sub1 .'</a> ';
$centerPage .= ' <span class="pagNumActive">'. $pn .'</span> ';
$centerPage .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='. $add1 .'">'. $add1 .'</a> ';
}
$paginationDisplay = '';
if($lastPage != '1'){
$paginationDisplay .= 'Page <strong>'.$pn.'</strong> of '.$lastPage.' ';
if($pn != 1){
$previous = $pn - 1;
$paginationDisplay .= ' <a href="'.$_SERVER['PHP_SELF'].'?page=1">First</a> ';
$paginationDisplay .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='.$previous.'">Back</a>';
}
$paginationDisplay .= '<span class="paginationNumbers">'.$centerPage.'</span>';
if($pn != $lastPage){
$nextPage = $pn+1;
$paginationDisplay .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='.$nextPage.'">Next</a>';
$paginationDisplay .= ' <a href="'.$_SERVER['PHP_SELF'].'?page='.$lastPage.'">Last</a> ';
}
}
每当我尝试运行此演示页面时,都会出现错误...这是错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“LIMIT0,10”附近使用正确的语法
警告:mysql_fetch_array():提供的参数不是第 87 行 G:\Backup\US\root\php-db\dashboard-2.php 中的有效 MySQL 结果资源
$limit = 'LIMIT'.($pn-1)*$itemPerPage.','.$itemPerPage;
$sql2 = mysql_query("SELECT * FROM emp ORDER BY emp_id $limit");
$outputList = '';
while($row = mysql_fetch_array($sql2)){
$id = $row["emp_id"];
$fname = $row["emp_fname"];
$lname = $row["emp_lname"];
$email = $row["emp_email"];
$desc = $row["emp_desc"];
$outputList = '
<tr>
<td>'.$id.'</td>
<td>'.$fname.'</td>
<td>'.$lname.'</td>
<td>'.$email.'</td>
<td>'.$desc.'</td>
<td>
<a href="view.php?id='.$id.'" title="View details..."><img src="assets/img/view.png" alt="View" /></a> | <a href="edit.php?id='.$id.'" title="Edit details..."><img src="assets/img/edit.png" alt="Edit" /></a> | <a href="delete.php?id='.$id.'" title="Delete details..."><img src="assets/img/delete.png" alt="Delete" /></a></td>
</tr>
';
}
?>
<html>
<head>
<title>
Employee dashboards!!!!
</title>
<style type="text/css">
.pagNumActive {
color: #000;
border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:link {
color: #000;
text-decoration: none;
border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:visited {
color: #000;
text-decoration: none;
border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:hover {
color: #000;
text-decoration: none;
border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:active {
color: #000;
text-decoration: none;
border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
</style>
</head>
<body>
<center>
<?php echo $paginationDisplay; ?>
</center>
<table cellpadding="5" cellspacing="4" border="4" width="100%" >
<thead>
<tr>
<th>Employee ID</th>
<th>Employee First Name</th>
<th>Employee Last Name</th>
<th>Employee Email ID</th>
<th>Employee Bio</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php echo $outputList; ?>
</tbody>
</table>
<center>
<?php echo $paginationDisplay; ?>
</center>
</body>
</html>