我已成功将MySQL数据输出到HTML表格中,并确切地说我想要它。现在,我想基于多个下拉值和提交按钮过滤此数据。我在教程和其他问题中四处寻找,但找不到我想要的东西。这是我输出的方式:
$fetchResult = "SELECT a.MembershipID, a.FirstName, a.Surname, t.RaceID, r.RaceName, t.Time, r.RaceID, r.ClubYear
FROM Athlete AS a
INNER JOIN Time AS t
ON a.MembershipID=t.MembershipID
INNER JOIN Race AS r
ON t.RaceID=r.RaceID
ORDER BY a.Surname";
$result = $mysqli->query($fetchResult);
//Start table
echo "<table>";
echo "<tr>
<th>First Name</th>
<th>Surname</th>
<th>Race</th>
<th>Time</th>
<th>Club Year</th>";
// Loop through database
while ($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td>' . $row['FirstName'] . '</td>';
echo '<td>' . $row['Surname'] . '</td>';
echo '<td>' . $row['RaceName'] . '</td>';
echo '<td>' . $row['Time'] . '</td>';
echo '<td>' . $row['ClubYear'] . '</td>';
}
echo "</tr></table>";
现在我有4个下拉列表也填充了数据库中的数据。我想要发生的是,用户选择1到4个下拉菜单中的选项,并且HTML中的数据被过滤但我无法使其工作。以下是我到目前为止的情况:
if (!empty($clubYear)) {
$fetchResult = "SELECT a.MembershipID, a.FirstName, a.Surname, t.RaceID, r.RaceName, t.Time, r.RaceID, r.ClubYear
FROM Athlete AS a
INNER JOIN Time AS t
ON a.MembershipID=t.MembershipID
INNER JOIN Race AS r
ON t.RaceID=r.RaceID
WHERE r.ClubYear='$clubYear'
ORDER BY a.Surname";
}
$result = $mysqli->query($fetchResult);
所以我检查下拉列表是否为空,如果没有,请使用WHERE过滤器应用查询。这只会使页面刷新并转到“无数据接收”页面。我哪里错了?应该根据下拉列表中选择的内容应用过滤器,但不明确说明下拉列表等于什么,即=如果$ clubYear ==“what”,那么WHERE r.ClubYear =“whatever” - 我想过滤掉传递变量。
感谢。