">Edit Restraunt Deta-6ren">
gpt4 book ai didi

php - sql查询只返回一行

转载 作者:行者123 更新时间:2023-11-29 13:09:41 25 4
gpt4 key购买 nike

此代码仅从表中返回一行,我无法弄清楚

    <?php
$sqlrest="Select `restaurant_name` , `restaurant_id` , `menuimage` from `restaurant` where `restaurant_id` = '".mysql_real_escape_string($_REQUEST['res_id'])."'";
$result=mysql_query($sqlrest) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$c=$row['restaurant_name'];
$id=$row['restaurant_id'];

<tr>
<td><?php echo $c ; ?></td>
<td><img src="image/<?php echo $resid=get::getimage($id); ?>" width="100" height="100" /></td>
<td><a href="editrestrauntdetails.php?res_id=<?php echo $id ; ?>">Edit Restraunt Details</a></td>
<td><a href="restaurantdelete.php?res_id=<?php echo $id ; ?>" onClick="return confirmdelete();">Delete</a></td>
</tr>
<?php } ?>

正在使用的函数代码

function getimage($catid) {
$image="select * from `restimage` where `res_id`='$catid' ";

$imageresult=mysql_query($image) or die(mysql_error()) ;
while($row=mysql_fetch_assoc($imageresult)){
return $getimage=$row['rest_image'];
}
}

最佳答案

如果您想要一家餐厅的所有图片。您的图像函数应该返回所有图像并返回它。也许是整个 img 标签。

function getimage($catid) {
$image="select * from `restimage` where `res_id`='$catid' ";

$imageresult=mysql_query($image) or die(mysql_error()) ;
$images = array();
while($row=mysql_fetch_assoc($imageresult)){
$images[] = '<img src="image/'. $row['rest_image'] .'" width="100" height="100" />';
}
return implode('', $images);
}

关于php - sql查询只返回一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22259389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com