0
我想从两个表中获取数据。我在一张桌子上有耐心的姓名和身份证,在其他桌子上有预约时间。如何格式化我使用PHP从两个表中获取的数据?
Table1:
Name Id
Joe Wang 1234
Jack Steward 5555
Table2:
Id Month Date
1234 Jan 15
1234 Jan 18
1234 Feb 5
1234 Mar 1
1234 Mar 3
5555 Jan 3
5555 Apr 4
5555 Apr 12
...
我得到的数据:
$stmt = $mysqli->prepare("SELECT Name,
Table1.Id,
Month,
Date
FROM Table1 JOIN Table2
WHERE Table1.Id=Table2.Id");
我怎样才能得到这样的输出:
Joe Wang
1234
Jan
15
18
Feb
5
Mar
1
3
Jack Steward
5555
Jan
3
...
我用的是下面的PHP代码,它会至少有一个名字,我D,月多次,
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
printf("\t<p>Name: %s Id: %s %s %s</p>\n",
htmlspecialchars($row["Name"]),
htmlspecialchars($row["Id"]),
htmlspecialchars($row["Month"]),
htmlspecialchars($row["Date"])
);
}
在此先感谢!
您使用一个循环,就像您一样,然后跟踪每个“列”并仅在其更改时输出新的列标题。不,我们不会为你写。这是你的工作。写一些东西,然后我们会尽力帮助解决它。 – 2013-04-08 03:44:15
使用'[$ id] [$ month] [] = $ date;' – 2013-04-08 03:44:45
创建3d数组实际的数据集越大,项目越多。我不能简单地使用3D数组。请问如何跟踪每个“栏目”? – juju 2013-04-08 05:00:16