0

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'];
}
}
6
  • 2
    because you have a return inside the loop as return $getimage=$row['rest_image']; so it always returns first row. Commented Mar 7, 2014 at 19:52
  • @AbhikChakraborty i did it something like this $getimage=$row['rest_image']; } return $getimage ; } Commented Mar 7, 2014 at 19:56
  • You are selecting one row by $_REQUEST['res_id'] from the table "restaurant" Commented Mar 7, 2014 at 19:57
  • So then, you want all the images for a given restaurant_id, right?? Commented Mar 7, 2014 at 19:59
  • @Marcel but it specifies only condition correct me if i am wrong Commented Mar 7, 2014 at 19:59

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

3 Comments

please change the variablename, this is a bad style us3.php.net/manual/en/reserved.keywords.php
@demonking Thanks, i renamed my variable.
@Marcel now it is not returning first row and it echoes width="100" height="100" / this at the end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.