2012-07-05 44 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