gpt4 book ai didi

php - 从mysql中的第二个表行获取记录

转载 作者:行者123 更新时间:2023-11-29 04:23:05 27 4
gpt4 key购买 nike

我有 2 个具有相同字段名称的表,我想显示来自两个字段列的记录。

Table_a
id date user test
1 2013-08-08 Adam Various
2 2013-08-08 Paul Record

Table_b

id date user test
1 2013-08-08 Adam Record
2 2013-08-08 Paul Mytest


$sql = "Select Table_a.date, Table_a.user, Table_a.test, Table_b.date, Table_b.user, Table_b.test FROM table_a, Table_b where Table_a.user like table_b AND table_a.Date = table_b.date AND table_b.Date = '".date("Y-m-d", strtotime("today"))."'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);


echo "<p'><b>" . $row['user'] . "</b></p>";
echo "<p><b>". $row['test'] ."</b></p>";
echo "<p><b>". $row['test'] ."</b></p>";

例如,我希望结果为 Adam -various -record。也就是说,我想要第三个 echo "<p><b>". $row['test'] ."</b></p>";显示来自 table_b 的记录。

谢谢

最佳答案

你可以使用 SQL 别名

SELECT column_name AS alias_name

代码示例

$sql = "SELECT Table_a.date AS tableA_date, 
Table_a.user AS tableA_user,
Table_a.test AS tableA_test,
Table_b.date AS tableB_date,
Table_b.user AS tableB_user,
Table_b.test AS tableB_test
FROM Table_a AS tableA,
Table_b AS tableB
WHERE tableA_user
LIKE tableB
AND tableA_date = tableB_date
AND tableD_date = '".date("Y-m-d", strtotime("today"))."'";

关于php - 从mysql中的第二个表行获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18096154/

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