I need to display specific value of key 'pasdiz_alus' from array $form->data into a table cell. And I need to display this table row only if value of key 'pasdiz_alus' is greater than '0'.
The code for this is below, but the problem is that output displays also the value of key 'pasdiz_alus' above my table row and there it is displayed as many times as number of keys of array.
How can I get rid of this display of value of ” 'pasdiz_alus' x times of number of keys in array (in my case 29 times – there are 29 keys in the array)”? In this case it is: 5454545454545454……
My code is:
<table style="width: 800px;">
<tbody>
<?php
if ($form->data['pasdiz_alus'] > 0){
echo '<tr><td style="width: 100px;">Bilde šeit</td><td style="width: 500px;"> <strong>Pašdizainēts alus</strong></td>';
foreach($form->data as $key => $value) {
if($key === 'pasdiz_alus')
echo '<td style="width: 100px;">';
echo $form->data['pasdiz_alus'];
echo '</td>';
}
echo '<td style="width: 100px;">Cena šeit</td></tr>';
}
?>
</tbody>
</table>
And this is the output display, in this case the value of 'pasdiz_alus' is 54
The first row is the “wrong” one that I need to get rid off, and the second row is the “right” one.
5454545454545454545454545454545454545454545454545454545454
Bilde šeit Pašdizainēts alus 54 Cena šeit
Thanks for helping!
Brgds, Raivis
The problem in your script is here:
Why do you cycle all the array keys, instead of directly accessing it?
This should solve your problem, but I’d recommend also to move the
ifpart before even opening the table: