我正在尝试从 mysql 填充多个表,并按 id 对它们进行排序。我不知道该怎么做,在这里也找不到太多。
目前我只从 mysql 填充一个表,但我已经在我的 mysql 表中添加了一个新列,这将是每个表的特定 id - 虽然不知道如何循环这个。
在预测表中,我有一列名为 'accid' 。我希望此列将一组具有相同“acid”的结果组合在一起并插入到 html 表中。我该怎么做呢?
这是我目前所拥有的:
$result = mysql_query("SELECT results.home_team, results.away_team, results.home_id,
results.away_id, results.ht_score, results.ft_score, predictions.draw,
predictions.winningid
FROM results
LEFT JOIN predictions ON results.match_id = predictions.matchid
WHERE userid='".$_SESSION['id']."' ORDER BY home_team");
$num_rows = mysql_num_rows($result);
if($num_rows) {
$wonBet = true; #ADDED
$notlong = false;
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
if(!$row["ht_score"]) {
$halftime = "-";
} else {
$halftime = $row["ht_score"];
}
if(!$row["ft_score"]) {
$fulltime = "-";
} else {
$fulltime = $row["ft_score"];
}
echo "<td>" . $row["home_team"] . "</td>" . "<td>" . " vs " . "</td>" . "<td>" . $row["away_team"] . "</td>" . "<td>" . $halftime . "</td>" . "<td>" . $fulltime . "</td>";
$value = $fulltime;
$apart = explode('-',$value);
if($apart[0] > $apart[1] && $row["home_id"]==$row["winningid"]) {
$hometeamwin = "Win";
} else if($apart[0] < $apart[1] && $row["away_id"]==$row["winningid"]) {
$hometeamwin = "Win";
} else if($apart[0] == $apart[1] && !$row["winningid"]) {
$hometeamwin = "Win";
} else {
$hometeamwin = "lose";
#ADDED
}
if($fulltime!=$row["ft_score"]) {
$hometeamwin = "";
}
if($hometeamwin == "lose"){ #ADDED
$wonBet = false; #ADDED
}
if($hometeamwin == ""){ #ADDED
$notlong = true; #ADDED
}
echo "<td>" . $hometeamwin . "</td>";
echo "</tr>";
}
echo '</table>';