2012-07-05 80 views
1

使用示例我發現here我正在使用下面的代碼創建一個帶有PHP的表格。然而,當我運行它,我收到以下錯誤:MySQL到PHP的HTML表格中

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /homepages/2/d333603417/htdocs/locationsconsole.php on line 94

線的我的代碼94是while (($row = mysql_fetch_assoc($query)) !== false) {

可能有人也許請告訴我,我有解釋的代碼錯誤,或者是有一個代碼錯誤。我只是想知道是否有人可以看看這個問題,並提供一些關於如何糾正這個問題的指導。

許多的感謝和親切的問候

<form name="locationsconsole" id="locationsconsole" method="post" action="locationsaction.php"> 
<?php 
$query = "SELECT l.*, COUNT(f.locationid) totalfinds FROM detectinglocations l LEFT JOIN finds f ON f.locationid = l.locationid WHERE l.userid = '27' GROUP BY l.locationname"; 
?> 

<table> 
<thead> 
<tr> 
    <th width="62"><div align="center">Location Name</div></th> 
    <th width="120"><div align="left">Location Address</div></th> 
    <th width="81"><div align="center">No. Of Finds Made </div></th>        
</tr> 
</thead> 
<tbody> 
<?php 
    while (($row = mysql_fetch_assoc($query)) !== false) { 
?> 
<tr> 
<td><?php echo $row['locationname']; ?></td> 
    <td><?php echo $row['returnedaddress']; ?></td> 
    <td><?php echo $row['totalfinds']; ?></td> 
    </tr> 
<?php 
} 
?> 
</tbody> 
</table> 
</form> 
+0

什麼是表1?你不應該有一個「檢測位置AS 1」嗎? – Sablefoste 2012-07-05 17:21:34

+0

@SableFoste:它實際上是字母「L」。至於......'AS' ......它隱含着:) – Ryan 2012-07-05 17:23:02

回答

1

您需要在獲取結果之前,實際上執行查詢,使用mysql_query

$sql = "SELECT l.*, COUNT(f.locationid) totalfinds FROM detectinglocations l LEFT JOIN finds f ON f.locationid = l.locationid WHERE l.userid = '27' GROUP BY l.locationname"; 
$query = mysql_query($sql); 

但是,請注意,mysql_擴展氣餒並且將在未來版本的PHP中被刪除,因此我建議您儘可能地切換到PDO或MySQLi。

+0

嗨@minitech,感謝您花時間回覆我的帖子,它效果很好。也感謝您的指導。 MySQL擴展。親切的問候 – IRHM 2012-07-05 17:25:50