Tuesday, August 27, 2013

How to show user image and name in html dynamically

How to show user image and name in html dynamically

Below is my code i want to show user image and name assign to it.which is
array coming from controller so i iterate it and put it in td of table.The
records coming from database are not fixed(it can be 5 or 10 and many
more).The problem is that when it shows image and name assign to it is
coming in same row irrespective of users.i want to break td after some
record from foreach. for example:
image1 image2 image3 image4 image5 image6 image7 image8
name1 name2 name3 name4 nam5 nam6 name7 name8
but i want it like this
image1 image2 image3 image4
name1 name2 name3 name4
image5 image6 image7 image8
nam5 nam6 name7 name8
Thanks.
<table>
<?php
$userid=$this->id;
$namearray=$this->name;
$imagearray=$this->image;
$length=$this->length;
?>
<tr>
<?php
for($i=0;$i<$length;$i++) {
?>
<td>
<a href="<?php echo
$this->url(array('username' => $userid[$i]),
'user') ?>"><img src="<?php echo
$imagearray[$i];?>" height="100"
width="100"></img></a>
</td>
<?php
}
?>
</tr>
<tr>
<?php
for($i=0;$i<$length;$i++) {
?>
<td>
<a href="<?php echo
$this->url(array('username' => $userid[$i]),
'user') ?>"><?php echo $namearray[$i];?></a>
</td>
<?php
}
?>
</tr>
</table>

No comments:

Post a Comment