Reputation: 357
I would like to hide each Parent DIV for each value that is empty or has no text. For example, if the fruits PHP value didn't return anything, I would like it's parent DIV hidden.
<div>
<span><font size="6" color="green"><u>FRUITS</u></font></span>
<br>
<span class="salad"><?php echo $row1['fruits']; ?></span>
<br><br>
</div>
<div>
<span><font size="6" color="green"><u>VEGGIES</u></font></span>
<br>
<span class="salad"><?php echo $row1['veggies']; ?></span>
<br><br>
</div>
Upvotes: 1
Views: 307
Reputation: 771
Use if condition. if you are sure that $row1['fruits'] may return a null value , u can use @ in-front of the variable to suppress the warning also. Hope this helps to sort your issue.
<?php if(@$row1['fruits']): ?>
<div>
<span><font size="6" color="green"><u>FRUITS</u></font></span>
<br>
<span class="salad"><?php echo $row1['fruits']; ?></span>
<br><br>
</div>
<?php endif; ?>
Upvotes: 0
Reputation: 807
if value is null then hide the div
<div <?php if(empty($val['fruits']))){ echo 'style="display:none;"'; }else{ echo ''; }?>>
<span><font size="6" color="green"><u>Fruit</u></font></span>
<br>
<span class="salad"><?php echo $val['fruits']; ?></span>
<br><br>
</div>
Upvotes: 0
Reputation: 11122
You can wrap it with an IF condition :
<?php if($row1['fruits']) { ?>
<div>
<span><font size="6" color="green"><u>FRUITS</u></font></span>
<br>
<span class="salad"><?php echo $row1['fruits']; ?></span>
<br><br>
</div>
<?php } ?>
Upvotes: 1
Reputation: 54831
Check if variable is empty
and add a style:
<div <?=empty($row1['fruits'])? ' style="display:none;"' : ''?>>
<span><font size="6" color="green"><u>FRUITS</u></font></span>
<br>
<span class="salad"><?php echo $row1['fruits']; ?></span>
<br><br>
</div>
Upvotes: 1