tags:

views:

37

answers:

3

Hi
This is my foreach function

<? foreach($Selected as $row)
     $value = $row['dPath'];
     $imgp =  base_url()."images"."/".$value;
{?>


<td>
  <?=$row['dFrindName'].'</br>';?>
  <?php */?> <img src="<?=$imgp ?>" name="b1" width="90" height="80" border="0"/>
</td>
<? }}?>
Print_r($Selected);
results in `Array ( [0] => Array ( [dFrindName] => chandruCP 
                    [dPath] => m11on.gif ) [1] => Array ( [dFrindName] => udaya 
                    [dPath] => logo.jpg ) )`

but only my last value of the array is displayed on image I can get the name udaya and logo.jpg on the screen But i cant get chandruCP and m11on.gif why it is so how can i get all the values and image on scrren

A: 

try

foreach ($Selected as $sel) {

echo "$sel->dpath"; 

}

Santana
@ SANTANA Message: Trying to get property of non-objectThis is the result
udaya
+1  A: 

Ok,

I think I got it

    <? 
    foreach($Selected as $row) {
        $value = $row['dPath'];
        $imgp =  base_url()."images"."/".$value;
    ?>  
        <td>
          <?=$row['dFrindName']."</br>";?>
          <img src="<?=$imgp; ?>" name="b1" width="90" height="80" border="0"/>
        </td>
<?

    }
?>
Santana
+2  A: 

There are a few things wrong with your code:

  1. The opening bracket { of your foreach is in the wrong place.
  2. You have a random closing comment in the middle of your code
  3. You are using invalid HTML, the correct way to write a self-closing is <br />

Here is your code rewritten to correct these errors, it should produce what you are trying to achieve:

<?
foreach ($Selected as $row) {
  $imgp =  base_url()."images"."/".$row['dPath'];
?>
  <td>
    <?=$row['dFrindName'];?><br />
    <img src="<?=$imgp;?>" name="b1" width="90" height="80" border="0" />
  </td>
<? } ?>
akamike