学习如何为我的体育联盟网站加入 MySQL 表。这似乎是一个相对简单的问题。如果有人可以在这里帮助澄清我的思考过程,将不胜感激:
我有一个联赛日程页面,它为“test_league”MySQL 表中的每场比赛生成带有比赛信息的 HTML 表格行。其中一个 HTML 列旨在通过提取主队的位置数据来显示该比赛的位置,该位置数据存储在同一数据库的“user_schools”表中。
我确切地知道我想做什么,我似乎无法完全正确地使用语法。这是代码:
<?php
// Connect to the database:
require ('../mysqli_connect.php');
// Make the query for games from the schedule database:
$q = "SELECT game_date, game_time, away_team, home_team, home_score, away_score, arbiter_id FROM test_league";
$r = mysqli_query($db, $q);
// Make the query to determine where the games will be played:
$location = mysqli_query($db, "SELECT football_location FROM user_schools WHERE home_team=school_name INNER JOIN test_league");
$map = mysqli_query($db, "SELECT football_map FROM user_schools WHERE home_team=school_name INNER JOIN test_league");
// Declare two variables to help determine the background color of each row:
$i = 0;
$bgcolor = array('row1', 'row2');
// Begin function to print each game as a row:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr class="' . $bgcolor[$i++ % 2] .'"><td>' . $row['game_date'] . '</td><td>' . $row['game_time'] . '</td><td class="alignleft"><a href="">' . $row['away_team'] . '</a> vs<br><a href="">' . $row['home_team'] . '</a></td>';
// Determine if the score has been reported:
if ($row['home_score'] == '0' && $row['away_score'] == '0') {
echo '<td><a href=""><img src="images/report_icon.png" alt="Report Score" /></a></td>';
} else {
echo '<td>' . $row['home_score'] . '<br>' . $row['away_score'] . '</td>';
}
echo '<td><a href="' . $map . '">' . $location . '</a></td><td><a href="">' . $row['arbiter_id'] . '</a></td></tr>';
}
mysqli_free_result ($r);
mysqli_close($db);
?>
如果需要澄清,“home_team”位于“test_league”中,“team_name”位于“user_schools”中。
我已经看到了使用表连接的维恩图插图,但似乎无法执行这个看似简单的任务。非常欢迎您的建议!