php - sql查询只返回一行

标签 php mysql sql

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

    <?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/

相关文章:

java - ActionListener 不适用于所有对象

SQL - 多行合二为一

php - MySQL加入及最新批处理信息

PHP GET 控制语句

MySQL 比较、计数和排序

mysql - 对同一列使用多个 between 子句

用于检索数值并打印为单词的 SQL 查询

PHP函数检查浏览器引用是否为空?

java - 在 PHP 中复制 Java 的 AES/CBC/PKCS5Padding 加密

php - 如何在mysql中从2个数据中找到减号?