我正在尝试制作一个“锦标赛”应用程序,并且无法查看来自6个不同表格的数据!
我有6个表格,我可以同时放入数据,但我无法一起查看!并试图在互联网上搜索几个小时,但我无法得到它......
无论如何。这是一场4胜的比赛,包括胜利,平局,输球和积分。我有6个表:
这就是表格中的内容......
这是我的意见,它运作正常..
<?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>";
}
?>
这是制作“联赛/锦标赛”的开始。所有数据都在表格中。
我从一个教程中得到了这个代码,我曾经在我的网页上进行简单的现场编辑。虽然mabey我可以使用相同的输出代码,但在该网站上它只是来自单个表的新闻。
我已经阅读了一些关于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。
答案 0 :(得分: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中解释过的任何方式。这个答案有意义吗?