gpt4 book ai didi

php - 查看MySQL中6个表的数据

转载 作者:行者123 更新时间:2023-11-30 23:27:14 24 4
gpt4 key购买 nike

我正在尝试制作一个“锦标赛”应用程序,但在查看来自 6 个不同表格的数据时卡住了!

我有6个tabel可以同时放入数据,但是不能一起查看!并尝试在互联网上搜索几个小时,但我就是找不到...

任何方式。这是一个 4 队比赛,有胜、平、负和积分。我有 6 个表:

  • 锦标赛名称 - 身份证、姓名
  • 团队 - ID, team1, team2, team3, team4
  • 获胜 - ID, team1w, team2w, team3w, team4w
  • 画画 ID, team1d, team2d, team3d, team4d
  • 松动 - ID, team1l, team2l, team3l, team4l
  • 积分 - ID, team1p, team2p, team3p, team4p

这就是表格中的内容...

这是我的输入,它工作正常..

<?php
if(isset($_POST['submit'])) {
$cupname = $_POST['cupname'];
$team1 = $_POST['team1'];
$team2 = $_POST['team2'];
$team3 = $_POST['team3'];
$team4 = $_POST['team4'];

$zero = "0";

$result = mysql_query("INSERT INTO cupname (name) VALUES ('$cupname')");
$result = mysql_query("INSERT INTO teams (team1, team2, team3, team4) VALUES ('$team1', '$team2', '$team3', '$team4')");
$result = mysql_query("INSERT INTO wins (team1w, team2w, team3w, team4w) VALUES ($zero, $zero, $zero, $zero)");
$result = mysql_query("INSERT INTO draws (team1d, team2d, team3d, team4d) VALUES ($zero, $zero, $zero, $zero)");
$result = mysql_query("INSERT INTO looses (team1l, team2l, team3l, team4l) VALUES ($zero, $zero, $zero, $zero)");
$result = mysql_query("INSERT INTO points (team1p, team2p, team3p, team4p) VALUES ($zero, $zero, $zero, $zero)");
echo "<h1>Turnering og lag lagt til!</h1>";
}

?>

这是制作“联赛/锦标赛”的开始。所有数据都在表格中。

我从一个教程中获得了这段代码,我曾经对我的网页进行简单的现场编辑。虽然也许我可以使用相同的输出代码,但在该站点上它只是来自单个表的新闻。

我读过一些关于 UNION、LEFT JOIN、FULL JOIN 等的内容……但我没有理解。

这是我的“输出”代码:

<?php
$result = mysql_query("SELECT * FROM cupname ORDER BY id DESC");
$result = mysql_query("SELECT * FROM teams ORDER BY id DESC");
$result = mysql_query("SELECT * FROM wins ORDER BY id DESC");
$result = mysql_query("SELECT * FROM draws ORDER BY id DESC");
$result = mysql_query("SELECT * FROM looses ORDER BY id DESC");
$result = mysql_query("SELECT * FROM points ORDER BY id DESC");
while($row = mysql_fetch_array($result)) {
$i=$i + 1;
echo "<table>";
echo "<tr>";
echo $row['name'];
echo "</tr>";
echo "<tr><td><b>Lag</b></td>
<td><b>Seiere</b></td>
<td><b>Uavgjort</b></td>
<td><b>Tap</b></td>
<td><b>Poeng</b></td>
</tr><tr><td>";
echo $row['team1'];
echo "</td><td>";
echo $row['team1w'];
echo "</td><td>";
echo $row['team1d'];
echo "</td><td>";
echo $row['team1l'];
echo "</td><td>";
echo $row['team1p'];
echo "</td></tr><tr><td>";
echo $row['team2'];
echo "</td><td>";
echo $row['team2w'];
echo "</td><td>";
echo $row['team2d'];
echo "</td><td>";
echo $row['team2l'];
echo "</td><td>";
echo $row['team2p'];
echo "</td></tr><tr><td>";
echo $row['team3'];
echo "</td><td>";
echo $row['team3w'];
echo "</td><td>";
echo $row['team3d'];
echo "</td><td>";
echo $row['team3l'];
echo "</td><td>";
echo $row['team3p'];
echo "</td></tr><tr><td>";
echo $row['team4'];
echo "</td><td>";
echo $row['team4w'];
echo "</td><td>";
echo $row['team4d'];
echo "</td><td>";
echo $row['team4l'];
echo "</td><td>";
echo $row['team1p'];
echo "</td></tr></table><br /><hr /><br />";
}
?>

有人知道我应该做什么或不做什么吗?

感谢您的回答!

编辑:我只是得到空表的输出!只输出点,即 0。

最佳答案

您需要加入表格。从你的问题来看,你似乎已经对表的关系部分进行了排序(尽管我不完全确定我是否完全遵循它),所以这实际上是一个使用什么连接的问题:

内部联接 - 这将只返回所有表中数据匹配的记录:

select
tourn.id,
tourn.name
from
tournament
join teams team
on tourn.id=team.id
join wins win
on tourn.id=win.id

等等(我假设 tournament.ID 是其他相关的列)

现在,您可以将其更改为外连接,无论其他表中是否存在匹配的行,它都会从您的第一个表中返回行:

select
tourn.id,
tourn.name
from
tournament
right outer join teams team
on tourn.id=team.id
right outer join wins win
on tourn.id=win.id

我不完全确定我是否可以用我在 Q&A 中解释的任何方式更好地解释此答案中的很多内容我之前写过的。这个答案有意义吗?

关于php - 查看MySQL中6个表的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12639484/

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