gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:27:57 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com