好的,基本上,我想在 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'];
}