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

标签 php mysql

+------------------+
| Tables_employees |
+------------------+
| empid            | 
| aid              | 
| FirstName        | 
| LastName         | 
| Email            |
| Phone            |

<table id="exampleC" class="display" cellpadding="1" cellspacing="1" width="" style="font-size:small;">
    <thead>
        <tr>
            <th>1st Name</th> 
            <th>2nd Name</th>
            <th>Title</th>
            <th>Email</th>
            <th>Phone(D)</th>
            <th>Linkedin</th>   
        </tr>
    </thead>
    <tbody>
        <?php
        require_once 'tabconnect.php';
        if (isset($_GET['id'])) {
            $id = $_GET['id'];
            $data = mysqli_query($connection,"SELECT acquisition.aid,acquisition.aby,employees.empid,employees.aid,employees.FirstName,employees.LastName,employees.title,employees.email,employees.phone,employees.dphone,employees.LIUrl,employees.listatus FROM employees JOIN acquisition ON acquisition.aid=employees.aid where acquisition.aid=$id");

                while ($row3 = mysqli_fetch_array($data)) { ?>  
            <tr>
                <td><?php echo $row3['FirstName']; </td>
                <td><?php echo $row3['LastName']; ?</td>
                <td><?php echo $row3['title']; ?></td>
                <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>                                     
            </tr>                     
        <?php
                }
        }
        ?>
    </tbody>
</table>

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

最佳答案

不清楚您是要填写所有记录还是只填写有图标的记录,您可以检查如下字段:

<?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 
        } 
 ?>

关于php - 不要在 php 中显示 mysql 表中的空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45996035/

相关文章:

php - 如何在 cookie 值中保护用户 ID

php - 正则表达式 - 需要小改动

php - 此 PDO 代码如何防止 SQL 注入(inject)?

php - 从android studio到php到mysql的连接存储在phpmyadmin中

带连接条件的 MySql 查询

php - 使用 AJAX 在同一页面中调用特定 PHP 函数

php - 使用 php 搜索查询来搜索和下载 mp3 文件

mysql - SQL 或 NoSQL 的扩展和性能

mysql - 如何将 NULL 视为最小值?

mysql - 在 ubuntu 上安装工作台