【发布时间】:2020-01-29 20:59:35
【问题描述】:
我有两个名为 accounts
的 MySQL 表id username role
1 pete101 2
2 JohnnyA 1
3 Anno65 1
4 tom 1
5 koala3 2
名称为events
id date accountID
1 02-04-20 3
2 10-04-20 5
3 07-04-20 4
4 10-04-20 2
5 10-04-20 1
现在我想在 HTML 表格中显示来自角色“2”的帐户中日期为“10-04-20”的所有事件。
我使用这个查询:"SELECT * FROM events JOIN accounts ON events.accountID = accounts.id WHERE events.date = '10-04-20' AND accounts.role = '2'"
while($row = mysqli_fetch_array($result)){
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['date'] . "</td><td>" . $row['username'] . "</td><td>" . $row['accountID'] . "</td><br>";
}
这个查询(和 PHP)的结果是下一个:
id date username accountID
5 10-04-20 koala3 5
1 10-04-20 pete101 1
它显示了 accounts 表 id 的两倍,但我想要下一个回显:
id date username accountID
2 10-04-20 koala3 5
5 10-04-20 pete101 1
所以第一列是events表的id,最后一列(accountID)是accounts表的id
我该怎么做才能解决这个问题?
提前非常感谢!
【问题讨论】:
-
而不是 row['id']... 尝试 row[0], row[1]...
-
谢谢,$row[0] 成功了。非常感谢。