2013-09-24 126 views
0
<?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 .= '&nbsp;<span class="pagNumActive">'. $pn .'</span>&nbsp;'; 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $add1 .'">'. $add1 .'</a>&nbsp;'; 
}elseif($pn == $lastPage){ 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $sub1 .'">'. $sub1 .'</a>&nbsp;'; 
$centerPage .= '&nbsp;<span class="pagNumActive">'. $pn .'</span>&nbsp;'; 
}elseif($pn == 2 && $pn < ($lastPage - 1)){ 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $sub2 .'">'. $sub2 .'</a>&nbsp;'; 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $sub1 .'">'. $sub1 .'</a>&nbsp;'; 
$centerPage .= '&nbsp;<span class="pagNumActive">'. $pn .'</span>&nbsp;'; 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $add1 .'">'. $add1 .'</a>&nbsp;'; 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $add2 .'">'. $add2 .'</a>&nbsp;'; 
}elseif($pn > 1 && $pn < $lastPage){ 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $sub1 .'">'. $sub1 .'</a>&nbsp;'; 
$centerPage .= '&nbsp;<span class="pagNumActive">'. $pn .'</span>&nbsp;'; 
$centerPage .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='. $add1 .'">'. $add1 .'</a>&nbsp;'; 
} 

$paginationDisplay = ''; 
if($lastPage != '1'){ 
$paginationDisplay .= 'Page <strong>'.$pn.'</strong> of '.$lastPage.'&nbsp;&nbsp;&nbsp;'; 
if($pn != 1){ 
    $previous = $pn - 1; 
    $paginationDisplay .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page=1">First</a> '; 
    $paginationDisplay .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='.$previous.'">Back</a>'; 
} 
$paginationDisplay .= '<span class="paginationNumbers">'.$centerPage.'</span>'; 
if($pn != $lastPage){ 
    $nextPage = $pn+1; 
    $paginationDisplay .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='.$nextPage.'">Next</a>'; 
    $paginationDisplay .= '&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='.$lastPage.'">Last</a> '; 
} 
} 

我这里的错误每当我尝试运行此演示页...这里是错误:当我在php中运行这个分页页面演示时出现错误?

您的SQL语法错误;请检查与您的MySQL服务器版本相对应的手册,以便在第1行的'LIMIT0,10'附近使用正确的语法。

警告:mysql_fetch_array():提供的参数不是G中的有效MySQL结果资源:\ Backup \美国\ ROOT \ PHP-DB \上线87

$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> 
+0

看起来你需要一个空间在'LIMIT'之后 – andrewsi

回答

0
$limit = 'LIMIT'.($pn-1)*$itemPerPage.','.$itemPerPage; 

仪表板2.PHP LIMIT后需要一个空间。

$limit = 'LIMIT '.($pn-1)*$itemPerPage.','.$itemPerPage; 
相关问题