问题描述
请问我是不熟悉PHP / MysqL。 我有两张桌子。餐桌员工有(id,全名),餐桌员工有(id,staff_id)。 我打算进行查询以获取在出勤表中所有没有id为staff_id的职员。下面是我的PDO代码:
$att = $con->prepare('SELECT member_id FROM attendance');
$att->execute();
while ($att_fetch = $att->fetch()) {
$absent = $con->prepare('SELECT * FROM members WHERE id != "'.$att_fetch['member_id'].'" ');
$absent->execute();
$absent_fetch = $absent->fetch();
echo '
<tr>
<td class="name" data-id="'.$absent_fetch['id'].'">'.ucwords($absent_fetch['fullname']).'</td>
</tr>
';
}
令人惊讶的是,这将返回出席表中的所有职员。 请帮帮我
解决方法
我打算进行查询,以获取
test_data <- data.frame(x = 1:3,y = 1:3)
表中没有id
作为staff_id
的所有员工。
您不需要两个查询以及一些PHP逻辑。您可以使用attendance
在单个查询中获得所需的结果:
not exists