php - 如何通过选择名字丢弃表中的数据并获得新结果?
问题描述
目前在我的网站上,我有一个表格显示学生的所有数据,但我想通过选择学生的名字来获得新的结果。通过这样做,我应该有一个表格,显示他们的名字、姓氏、事件名称、事件长度、时间和仅针对该特定学生的排名,并且检查结果按钮也不起作用。因为我是新手,如果我能得到一些帮助会很好。非常感谢。
<form action = "result.php" method = "POST">
</form>
Select Student<br>
<select name="Stud">
<?php
//stores the query in the variable $all_names_query
$all_names_query ="Select * FROM Student ORDER BY FirstName ASC";
//Run the query and store the result in a variable called $all_names_results
$all_names_result=mysqli_query($dbcon, $all_names_query) ;
echo "<option value=>";
echo "Select Student";
echo "</option>";
//Fetching row of result as an associative array
while ($displayname=mysqli_fetch_assoc($all_names_result))
{
//Displaying the First Name of the Student in the drop down menu
echo "<option value='".$displayname['FirstName']."'>".$displayname['FirstName']."</option>";
}
?>
</select>
<p><input type = "submit" name = "submit" value="Check results"></p>
</form>
<table align="center" border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Event</th>
<th>Event Length</th>
<th>Time</th>
<th>Rank</th>
</tr>
<?php
while($record = mysqli_fetch_assoc($Student_result)) {
echo "<tr>";
echo "<td>".$record['FirstName']."</td>";
echo "<td>".$record['LastName']."</td>";
echo "<td>".$record['EventName']."</td>";
echo "<td>".$record['EventLength']."m</td>";
echo "<td>".$record['Time']."s</td>";
echo "<td>".$record['Rank']."</td>";
echo "</tr>";
}
?>
</table>
PHP:
<?php
if (isset($_POST['Stud'])){
$Student = $_POST['Stud'];
}
$Student_query = "SELECT Student.StudentID, Student.FirstName, Student.LastName, Event.EventID, Event.EventName, Event.EventLength, Result.Time, Result.Rank
From Student, Event, Result
WHERE Student.StudentID = Result.StudentID
AND Result.EventID = Event.EventID
ORDER BY Student.StudentID, Student.FirstName";
$Student_result = mysqli_query ($dbcon, $Student_query);
$Student_rows = mysqli_num_rows($Student_result);
//if ($Student_rows > 0) {
//echo "There were ".$Student_rows." results!!";
//}
//else {
//echo "No results found!";
//}
?>
解决方案
推荐阅读
- javascript - 受祝福的服务器(Node.js)通过 websocket 到浏览器中的 Xterm.js 客户端
- node.js - 使用 ng serve 找不到模块“@angular-devkit/build-angular”
- acumatica - 在用户更新并关闭智能面板后,如何在读取所有智能面板字段之前强制读取更新?
- sql-server - SQL Server:根据搜索另一个结果集从一个表中获取结果
- laravel - Vue.js 转换在 Laravel Blade + Sass 中不起作用
- core-ui - 添加具有默认布局的新组件
- python - 无法在 Gtk.TextView i Python 3 中对列进行排序
- javascript - 在数组中使用切片不会影响模板
- git - 如何恢复当前 git 提交的文件
- iphone - 如何使用蓝牙串行配置文件将串行数据发送到 Mac