就像在这个图像中两个空的字段我只想要那些如果这些字段是空的只是隐藏它们,如果它们包含任何值,那么它显示
这是代码
<?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>
答案 0 :(得分:1)
检查它们是否为empty
-
$val = trim($row['addaddress']);
if(!empty($val)) {
// display the table row or column
}
对于你的代码,它应该是 -
$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()
根据值使用检查。使用empty()
时,如果值为0
则为空。
答案 1 :(得分:0)
您可以使用if条件检查值是否为空。它不会回应html,它是空的。
<?php if(!empty($row['addcity'])): ?>
<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>
<?php endif; ?>
答案 2 :(得分:0)
需要解决非空状况:
<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"'><?php if(!empty($row['mobile'])){ echo "<b>Mobile No. ( ਮੋਬਿਲੇ ਨੋ. ) - </b> ".$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"'><?php if(!empty($row['landline'])){ echo"<b>Landline - </b> ".$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"'><?php if(!empty($row['addaddress'])){ echo"<b>Add. Address - </b> ".$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"'><?php if(!empty($row['addcity'])){ echo "<b>Add. VPO/City - </b> ".$row['addcity']."" ?><o:p></o:p></span></p>
<p> </p>
</td>
</table>