我想通过将ent
表中的att_card_no的值与att_user表中的cardno进行匹配来显示名称。在mysql中加入两个表并从第二个表读取值
try {
$att = $att->query('select att_time,att_date,att_card_no from att_detail WHERE att_card_no IN (select name from att_user where cardno="2342323423")');
$att -> execute();
$result = $att -> fetch();
}
catch (PDOException $e){
echo $att . "<BR>" . $e->getMessage();
}
$att -> execute();
?>
<?php echo "Name: ".$result['att_card_no']; ?>
Table:att_detail
+---------+----------+-------------+------------+
| no | att_time | att_date | att_card_no|
+---------+----------+-------------+------------+
| 1 | 08:01 | 11-12-17 | 2342323423 |
| 2 | 08:02 | 12-12-17 | 4574574577 |
| 3 | 08:03 | 13-12-17 | 4656456796 |
| 4 | 08:04 | 14-12-17 | 9343450984 |
+---------+----------+-------------+------------+
Table: att_user
+----+-------------+-------------+
| no | name | cardno |
+----+-------------+-------------+
| 1 | name1 | 2342323423 |
| 2 | name2 | 4574574577 |
| 3 | name3 | 4656456796 |
| 4 | name4 | 9343450984 |
+----+-------------+-------------+
但是不显示来自att_user的名称值。感谢您了解这里出了什么问题。也没有错误抛出。
编辑:如果你不能回答这个问题,或者如果您发现类似Q,解决了我的问题,请让我知道,因为我的搜索没有找到任何而是反对投票这个问题是没有帮助一点
为什么要“名”显示,如果你不选择它?你为什么认为“att_card_no”在“select name ...”中? –
@ MichaelO.如果您滚动浏览,则可以看到我确实在第二个表att_user中选择了它。检查表 – X10nD
'WHERE att_card_no IN(select name'没有意义,因为'att_card_no'是一个包含数字的列,'name'是一个包含字符串的列 –