21,880
社区成员
发帖
与我相关
我的任务
分享
$sql="select * from member";
$res=mysql_query($sql);
while($arr=mysql_fetch_assoc($res)){
$data[]=$arr;
//echo $arr['username'];
}
$data[]=$arr
啊? 不加的话是一维数组不是也可以直接用吗?为什么要变成二维数组再用 foreach遍历啊?一直搞不明白,希望各位能指点一下,谢谢。function getimg($product_id,$result_type=MYSQL_ASSOC){
$sql="select i.path from img i where pid={$product_id}";
$result = mysql_query($sql);
while(@$row=mysql_fetch_array($result,$result_type)){
$rows[]=$row;
}
return $rows;
}
在index.php里有 <li class="span3">
<div class="offer">
<figure>
<?php
$getimg=getimg($place['id']);
foreach($getimg as $img):
?>
<a href="place_detail.php?id=<?php echo $place['id']; ?>"> <img src="Images/place/<?php echo $img['name'];?>" style="width:270px;height:167px;" alt="Offer Image"> </a>
<?php endforeach; ?>
</figure>
</div>
</li>
这里的foreach是为了循环<figure>对吗?在这里用while也可以吧?不好意思,初学者,还望指教,谢谢您。