[英]Redirecting on click with php
我需要幫助的是,當有人選擇哪個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>
不幸的是,我無法完全理解你。 但是,我打算為您提供幫助。 我認為您需要什么:
使用點擊的值將用戶重定向到另一個頁面
您的表格文件:
<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代碼)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.