好的,基本上,我想在foreach循环中循环mysql_fetch_array,如下所示:
foreach($groupname as $group)
{
$sql2=mysql_query("SELECT * FROM groups WHERE group='$group'");
$row2=mysql_fetch_array($sql2);
?>
<img src="images/groups/" width="100px" height="100px" /><br />
<table>
<tr><td><b>Group: </b></td><td><?php echo $group; ?></td></tr>
<tr><td><b>Description: </b></td><td><?php echo $row2['description']; ?></td></tr>
</table><br /><br /><br />
<?php
}
?>
所以当我这样做时,我得到以下mysql错误:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...
有什么方法吗?
注意:在我做foreach循环之前,我做一个while循环,我循环通过一个mysql表,实际上成功了。这是while循环的代码片段:
$groupname=array();
$sql=mysql_query("SELECT * FROM joined WHERE email='$email'");
while($row=mysql_fetch_array($sql))
{
$groupname[]=$row['group'];
}
答案 0 :(得分:1)
group
是mysql keyword,因此您需要将其括在反引号中:
WHERE `group` = ...
答案 1 :(得分:1)
您始终可以使用mysql_error()
即
$sql2=mysql_query("SELECT * FROM groups WHERE `group`='$group'") or die(mysql_error());
但失败了,因为group
是保留字http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
在group
-
SELECT * FROM groups WHERE `group`='$group'