2014-04-10 76 views
-2

該代碼工作正常,在本地主機上只有幾頁,但這不是在服務器上工作,並顯示一些排序警告,如"mysql_num_rows() expects parameter 1 to be resource, boolean given in /home2/tp/public_html/ols/admin/delete-employee.php on line 23。它總是讓我困惑,因爲它在某個頁面上工作,並且在某個時候顯示一條警告信息,這讓我感到很沮喪。警告:mysql_num_rows()期望參數1是資源。

幫助,請..

<?php 
    include('includes/start.php'); 
    require_once('includes/header.html'); 
?> 
<?php 


$page_title = 'View Employees'; 

require_once("../dbcon.php"); 
$query = "SELECT 
    fname 
    , lname 
    , eid 
    , fname 
    , mname 
    , lname 
    , posid 
    , date_added 
FROM 
    ccse.employee"; 
$result = @mysql_query($query); 
$num = mysql_num_rows($result); 
if($num > 0){ 
    echo "<p align='center'>There are $num employees found on the system!</p>\n"; 

if($result){ 

echo '<table align="center" border="1" bgcolor="lightgreen"> 
<tr> 
<td colspan="111" align="center"><b>List of Employees</td></tr> 
<tr> 
<td align="center"><b>Employee ID</a></b></td> 
<td align="center"><b>First Name</a></b></td> 
<td align="center"><b>Middle Name</a></b></td> 
<td align="center"><b>Last Name</a></b></td> 
<td align="center"><b>Position</a></b></td> 
<td align="center"><b>Date Added</a></b></td> 
<td align="center"><b>Action</a></b></td> 
</tr>'; 

$bg = '#eeeeee'; 
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ 
$bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee'); 


echo '<tr bgcolor="'.$bg.'"> 
<td align="left">'.$row['eid'].'</td> 
<td align="left">'.$row['fname'].'</td> 
<td align="left">'.$row['mname'].'</td> 
<td align="left">'.$row['lname'].'</td> 
<td align="left">'.$row['posid'].'</td> 
<td align="left">'.$row['date_added'].'</td> 
<td align="left"><a href="del_emp.php?id='.$row['eid'].'"><img src="../images/delete.jpg" width="50" height="20"></a></td> 

</tr>'; 

} 

echo '</table>'; 
//------------------End of Get list of Employees-------- 
mysql_free_result($result); 
}else{ 
echo '<p class="error">There are currently no entered employees in the system!</p>'; 
/*echo '<p class="error">Data Can Not Be Retrieved!</p>'; 
echo '<p>'.mysql_error().'<br /><br />Query:'.$query.'</p>';*/ 
} 
mysql_close(); 

if($num_pages > 1){ 
echo '<br /><p>'; 
$current_page = ($start/$display) + 1; 

if($current_page !=1){ 
echo '<a href="profile_emp.php?s='.($start - $display).'&np='.$num_pages.'$sort='.$sort.'" />Previous</a>'; 
} 

for($i = 1; $i <=$num_pages; $i++){ 
    if($i !=$current_page){ 
    echo '<a href="emp-list.php?s='.(($display * ($i-1))).'&np='.$num_pages.'$sort='.$sort.'" />'.$i.'</a>'; 
    }else{ 
    echo $i.''; 
    } 
} 

if($current_page !=$num_pages){ 
echo '<a href="emp-list.php?s='.($start + $display).'&np='.$num_pages.'$sort='.$sort.'" />Next</a>'; 
} 
echo '</p>'; 
} 
//------End of Paging Result---- 

} 

?> 
<?php 
echo "<br>";echo "<br>"; 
include('../includes/footer.html'); 
?> 
+0

如果使用mysql_error(),它將顯示查詢中的錯誤位置 – gbestard

+2

1.不要使用'mysql_'函數。他們已被棄用**年**。使用'mysqli_''或PDO。 2.不要使用錯誤抑制運算符('@') - 它*隱藏*錯誤,這就是爲什麼您現在需要向我們尋求幫助。 – h2ooooooo

+0

爲什麼不檢查你的$結果?這是錯誤的; –

回答

0

原因MySQL_num_rows失敗是因爲$result可能只是false - 這發生在一個失敗的查詢。使用MySQL_error()來查找查詢中錯誤的位置 - 可能是一個錯誤的數據庫等等,而且我也建議您不要使用MySQL_函數,因爲它們已被棄用。改爲使用mysqli_

相關問題