duandi4815 2015-07-07 05:26
浏览 35
已采纳

在php中隐藏空字段值及其标签

Like in this image two fields which are empty i just want that if those fields are empty just hide them, and if they contains any value then it shows

Like in this image two fields which are empty i just want that if those fields are empty just hide them, and if they contains any value then it shows

Here is the Code

<?php
                                    $query = mysql_query("select * from clients where clients_id = '$get_id'")or die(mysql_error());
                                    $row = mysql_fetch_array($query);
                            ?>
<table>
<tr>
<td>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span style='font-size:12.0pt;mso-bidi-font-size:11.0pt;font-family:
"Times New Roman","serif"'><b>Mobile No. ( ਮੋਬਿਲੇ ਨੋ.  ) - </b> <?php echo $row['mobile']; ?><o:p></o:p></span></p>
<p> </p>
</td>

<td>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span style='font-size:12.0pt;mso-bidi-font-size:11.0pt;font-family:
"Times New Roman","serif"'><b>Landline - </b> <?php echo $row['landline']; ?><o:p></o:p></span></p>
<p> </p>
</td>
</tr>

<tr>
<td>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span style='font-size:12.0pt;mso-bidi-font-size:11.0pt;font-family:
"Times New Roman","serif"'><b>Add. Address - </b> <?php echo $row['addaddress']; ?><o:p></o:p></span></p>
<p> </p>
</td>
<td>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span style='font-size:12.0pt;mso-bidi-font-size:11.0pt;font-family:
"Times New Roman","serif"'><b>Add. VPO/City - </b> <?php echo $row['addcity']; ?><o:p></o:p></span></p>
<p> </p>
</td>

</table>
  • 写回答

3条回答 默认 最新

  • dtjwov4984 2015-07-07 05:29
    关注

    Add a check if they are empty or not -

    $val = trim($row['addaddress']);
    if(!empty($val)) {
         // display the table row or column
    }
    

    For you code it should be something like -

    $val = trim($row['addaddress']);
    if(!empty($val)) {
    ?>
        <td>
        <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
        normal'><span style='font-size:12.0pt;mso-bidi-font-size:11.0pt;font-family:
        "Times New Roman","serif"'><b>Add. Address - </b> <?php echo $row['addaddress']; ?><o:p></o:p></span></p>
        <p> </p>
        </td>
    <?php
    }
    

    Read this before using empty()

    Use the check depending on the values. With empty(), if the value is 0 it will be empty.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错