不要在mysql表中显示php中的空结果

时间:2017-09-01 08:23:27

标签: php mysql

{{ form_label(form.username) }}
{{ form_widget(form.username) }}
{{ form_errors(form.username) }}

{{ form_label(form.email) }}
{{ form_widget(form.email) }}
{{ form_errors(form.email) }}

{{ form_label(form.plainPassword.first) }}
{{ form_widget(form.plainPassword.first) }}
{{ form_errors(form.plainPassword.first) }}

{{ form_label(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}

问题是它会显示所有电子邮件和手机图像,但我想只在表格中有记录时显示图像

2 个答案:

答案 0 :(得分:0)

<?php if ($row3['email'] && $row3['phone']) { ?>

 <td><a class="" href="<?php echo $row3['email']; ?>" target="_blank"><i class="icon-custom icon-sm rounded-x fa fa fa-envelope"></i></td>                                       
 <td><a class="" href="<?php echo $row3['phone']; ?>" target="_blank"><i class="icon-custom icon-sm rounded-x fa fa-phone"></i></td>  


<?php } ?>

检查手机和电子邮件是否为空,然后显示手机和电子邮件图标。

答案 1 :(得分:0)

目前尚不清楚您要填写所有记录还是只记录哪些记录,您可以查看以下字段:

<?php
    while ($row3 = mysqli_fetch_array($data)) { 
  ?>  
    <tr>
        <td><a class="" href="<?php echo ($row3['email'])?$row3['email']:''; ?>" target="_blank">
            <?php if($row3['email']!=''){ echo '<i class="icon-custom icon-sm rounded-x fa fa fa-envelope"></i>';
            }else{echo '';} ?></td>                                       
        <td><a class="" href="<?php echo ($row3['phone'])?$row3['phone']:''; ?>" target="_blank">
            <?php if($row3['email']!=''){ echo '<i class="icon-custom icon-sm rounded-x fa fa-phone"></i>'; }
            else{echo '';}</td>                                     
    </tr>                     
 <?php 
        } 
 ?>