php - 用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代码)
推荐阅读
- javascript - 创建简单 TeamViewer 克隆的最佳步骤
- node.js - Graphql 总是返回 null
- django - django 中的模板过滤器标签 - 过滤 {{activate_url}}
- java - 我可以让构造函数返回由于验证原因尚未初始化的值吗?
- pandas - 使用 PANDAS 代替 Spark
- python - 如何在python中对具有概率密度的积分函数进行曲线拟合?
- html - 调整页面大小时覆盖文本的共享按钮
- entity-framework-core - 无法翻译 LINQ 表达式“First()”并将在本地计算。使用 groupby 时
- java - 为什么我不能覆盖 ID
标签? - linux - 如何使用 Bash 获取仅包含一组字母的行?