Sunday, 25 August 2013

displaying table data from a multidimensional array

displaying table data from a multidimensional array

here is my array
Array
(
[0] => Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => no
)
[1] => Array
(
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => yes
)
[2] => Array
(
[0] => 3
[1] => 3
[2] => 3
[3] => 3
[4] => yes
)
[3] => Array
(
[0] => 4
[1] => 4
[2] => 4
[3] => 4
[4] => no
)
[4] => Array
(
[0] => 5
[1] => 5
[2] => 5
[3] => 5
[4] => yes
)
)
this is what i tried, i'm creating a tables tr portion and what it does is
duplicate itself for each record that is being displayed. How else can
this be written so that it displays correctly? I know it must be simple i
just cant wrap my head around it.
<?php
$units = json_decode($tablerow);
foreach($units as $unit) : for($i=0;$i<=count($unit)-1;$i++) : ?>
<tr class="rows">
<td><input type='text' name='bedroom[]' value='<?=$units[$i];?>'
class='input-small'></td>
<td><input type='text' name='bath[]' value='<?=$units[$i];?>'
class='input-small'></td>
<td><input type='text' name='sqrt[]' value='<?=$units[$i];?>'
class='input-small'></td>
<td><input type='text' name='price[]' value='<?=$units[$i];?>'
class='input-small'></td>
<td>
<select name='avail[]' class='input-small'>
<option value='yes' <?=($units[$i] == 'yes') ?
'selected="selected' : '';?>>Yes</option>
<option value='no' <?=($units[$i] == 'no') ? 'selected="selected'
: '';?>>No</option>
</select>
</td>
<td><button type="button" class="btn btn-danger btn-small
removeRow">remove</button></td>
</tr>
<?php endfor; endforeach; ?>

No comments:

Post a Comment