简体   繁体   中英

not to display empty results in php from mysql table

+------------------+
| 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>

Problem is that it will display all the email and phone images, but I want to display images only when there will be a records in table

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

Check if phone and email are not null and then display the phone and email icons.

Its not clear that you want to fill all the records or only record which have icons, you can check the fields like below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM