简体   繁体   中英

sql query returning only one row

this code is returning only one row from the table , i am unable to figure it out

    <?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 code that is being used

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'];
}
}

If You want all images from one restaurant. Your Image Function should return all images and return it. Maybe the whole img Tag.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM