我需要帮助的是有人选择哪个CRN(课程编号)
我需要将它们定向到另一个页面或表单,并将单击的按钮保存为值。 (重定向并将点击的值发送到该页面)
<table class="table table-bordered table-hover table-striped">
<thead>
<tr style="background-color:#f2f2f2">
<th>CRN</th>
<th>Section</th>
<th>Course Title</th>
<th>Start Time</th>
<th>End Time</th>
<th>Room Number</th>
</tr>
<?php $db = new mysqli('localhost', 'root', '', 'mydb');
if ($db-> connect_error){
die("connection_failed:".$db-> connect_error);
}
$sql ="SELECT CRN, section, Crse_Title, Crse_Start_Time, Crse_End_Time, Room_Num from section";
$result = $db -> query($sql);
if($result -> num_rows > 0){
while ($row = $result-> fetch_assoc()) {
echo "<tr>
<td><button class='btn btn-md' type='submit' name='section-submit'>".$row["CRN"]."</button></td>
<td>". $row["section"]. "</td>
<td>". $row["Crse_Title"]. "</td>
<td>". $row["Crse_Start_Time"]."</td>
<td>". $row["Crse_End_Time"]."</td>
<td>". $row["Room_Num"]."</td>
</tr>";
}
echo "</table>";
}
else {
echo "0 result";
}
$db -> close();
?>
</thead>
</table>
答案 0 :(得分:0)
很遗憾,我无法完全理解您。 但是,我打算为您提供帮助。 我认为您需要什么:
使用点击值将用户重定向到另一个页面
您的表格文件:
<table class="table table-bordered table-hover table-striped">
<thead>
<tr style="background-color:#f2f2f2">
<th>CRN</th>
<th>Section</th>
<th>Course Title</th>
<th>Start Time</th>
<th>End Time</th>
<th>Room Number</th>
</tr>
<?php
$db = new mysqli('localhost', 'root', '', 'mydb');
if($db->connect_error)
{
die("connection_failed:".$db->connect_error);
}
$sql="SELECT CRN, section, Crse_Title, Crse_Start_Time, Crse_End_Time, Room_Num from section";
$result = $db->query($sql);
if($result->num_rows > 0)
{
while ($row = $result->fetch_assoc())
{
echo "<tr>
<td><a href='course.php?id=".$row["CRN"]."' class='btn btn-md'>".$row["CRN"]."</a></td>
<td>". $row["section"]. "</td>
<td>". $row["Crse_Title"]. "</td>
<td>". $row["Crse_Start_Time"]."</td>
<td>". $row["Crse_End_Time"]."</td>
<td>". $row["Room_Num"]."</td>
</tr>";
}
//echo "</table>";
}
else
{
echo "0 result";
}
$db->close();
?>
</thead>
</table>
课程文件:
<?php
if(isset($_GET['id']))
{
//is_numeric()
$id=(int) $_GET['id'];
print "Current Course ID : " . $id;
}
?>
还有其他方法。(例如:编写JavaScript代码)