Excuse me, I have source for get value from table
foreach ($hard->result() as $row) {
$ha[] = $row->bek;
}
(bek is name of column and $hard isi name of variable return query)
then I wanna write the result with lopping too.
<?php
'<tr>';
$d = 0;
$g = 0;
$s = 0;
foreach ($mon->result() as $row) {
?>
<td class="tg-yw4l"><?php echo $row->sNama;?></td>
<td class="tg-yw4l"><?php echo $norm[$d++];?></td>
<td class="tg-yw4l"><?php echo $ha[$g++];?></td>
<td class="tg-yw4l"><?php echo $urg[$s++];?></td>
<td class="tg-yw4l"></td>
</tr>
<?php
}
?>
my question is : how to give '0', when the result from db doesn't give a value (null) Can someone help me please,,
Thanks before
You can try this
<?php
'<tr>';
$d = 0;
$g = 0;
$s = 0;
foreach ($mon->result() as $row) {
?>
<td class="tg-yw4l"><?php isset($row->sNama) ? echo $row->sNama : echo '0'; ?></td>
<td class="tg-yw4l"><?php isset($norm[$d++]) ? echo $norm[$d++] : echo '0'; ?></td>
<td class="tg-yw4l"><?php isset($ha[$g++]) ? echo $ha[$g++] : echo '0'; ?></td>
<td class="tg-yw4l"><?php isset($urg[$s++]) ? echo $urg[$s++]] : echo '0'; ?></td>
<td class="tg-yw4l"></td>
</tr>
<?php
}
?>
<?php
$res = $mon->result();
if($res && count($res)>0){
$d = 0;
$g = 0;
$s = 0;
foreach ($res as $row) { ?>
<tr>
<td class="tg-yw4l"><?php echo $row->sNama;?></td>
<td class="tg-yw4l"><?php echo $norm[$d++];?></td>
<td class="tg-yw4l"><?php echo $ha[$g++];?></td>
<td class="tg-yw4l"><?php echo $urg[$s++];?></td>
<td class="tg-yw4l"></td>
</tr>
<?php }
}
?>
thanks for all your attention to answer my case,
my problem is how to manipulate value from the table even when the value is empty
after I tried all way, I knew my case can't be fixed if I don't change my query because when I tried to loop with index 0, the result isnot still give '0'
foreach ($hard->result() as $row) {
$ha[0] = $row->bek;
}
<td class="tg-yw4l"><?php echo $ha[0];?></td>
because of that I knew, I should change my query in order if the result is empty it must give value '0'