首页 > 解决方案 > 如何通过选择名字丢弃表中的数据并获得新结果?

问题描述

目前在我的网站上,我有一个表格显示学生的所有数据,但我想通过选择学生的名字来获得新的结果。通过这样做,我应该有一个表格,显示他们的名字、姓氏、事件名称、事件长度、时间和仅针对该特定学生的排名,并且检查结果按钮也不起作用。因为我是新手,如果我能得到一些帮助会很好。非常感谢。

<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!";

//}

?>

标签: phpmysqlformsoption

解决方案


推荐阅读