问题描述:

I have multiple fields in a form that are storing data to database. on the front i have write the HTML for all the fields but i only want to show those fields that have value in database.

<?php if ($result['condition_en'] && ($result['condition_en'] != "Null")) { ?>

<tr>

<td width="19%" align="right" valign="middle" class="tdL">Condition</td>

<td width="81%"><?php echo $result['condition_en']; ?></td>

</tr>

<?php } ?>

<?php if ($result['construction_en'] && ($result['construction_en'] != "Null")) { ?>

<tr>

<td align="right" valign="middle" class="tdL" >Construction:</td>

<td><?php echo $result['construction_en']; ?></td>

</tr>

<?php } ?>

I have tried it in this way but nothing works any solution?

网友答案:

Try This:

<?php 
if(!empty($result['condition_en']))
{ 
?>
    <tr>
        <td width="19%" align="right" valign="middle" class="tdL">Condition</td>
        <td width="81%"><?php echo $result['condition_en']; ?></td>
    </tr>
<?php 
} 
?>
<?php 
if(!empty($result['construction_en'])) { ?>
    <tr>
        <td align="right" valign="middle" class="tdL" >Construction:</td>
        <td><?php echo $result['construction_en']; ?></td>
    </tr>
<?php 
} 
?>
网友答案:

Use Like:

<?php if (!empty($result['condition_en']) && isset($result['condition_en']) && $result['condition_en'] != NULL && $result['condition_en'] != "") { ?>
<tr>
<td width="19%" align="right" valign="middle" class="tdL">Condition</td>
<td width="81%"><?php echo $result['condition_en']; ?></td>
</tr>
<?php } ?>
网友答案:

Change your checking from

if ($result['condition_en'] && $result['condition_en'] != "Null")

To

if ($result['condition_en'] && $result['condition_en'] != "")

Because you are currently checking for the "Null" string rather than the NULL value itself. Better to check if the value is empty.

相关阅读:
Top