如果单元格内容为空,则在表格中显示消息

时间:2016-09-05 19:25:11

标签: php html mysql

我试图将mysql数据库中的值回显到表中,但是某些值可能为空,我不希望单元格输出为空。有没有办法让我显示一条消息,例如" N / A"如果数据库中的特定值为空?

<table><tr><td>Friends Name:</td><td><b>".$row['first_name']."&nbsp; ".$row['last_name']."</b></td></tr></table>

1 个答案:

答案 0 :(得分:0)

这样的东西
<table>
    <tr>
        <td>Friends Name:</td>
        <?php if($row['first_name']): ?>
            <td><b>".$row['first_name']."&nbsp; ".$row['last_name']."</b></td>
        <?php else: ?>
            <td><b>N/A</b></td>
        <?php endif; ?>
    </tr>
</table>
相关问题