我只想在一个表中显示我的数据库,表中的每一行都有一个复选框。用户可以选择选中一个或多个框,然后点击提交按钮,在另一个页面中查看所选数据。下面是我尝试的代码。
索引.php
<!--Adds column titles -->
<div style="overflow-x:auto;">
<table id="test_data">
<tr>
<th> Select </th>
<th> Test ID </th>
<th> Path </th>
<th> Video 1 Path </th>
<th> Video 2 Path</th>
<th> Video 3 Path</th>
<th> Video 4 Path</th>
</tr>
<!--Prints out data from test_data table-->
<?php
$sql = "SELECT * FROM test_data";
$result= mysqli_query($conn, $sql);
$queryResults = mysqli_num_rows($result);
if ($queryResults > 0) {
echo "<form action= 'search.php' method='get'>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td><input type='checkbox' name='checkbox_id' value='" . $test_id . "'> </td>
<td> ".$row['test_id']." </td>
<td> ".$row['path']." </td>
<td> ".$row['video1_path']." </td>
<td> ".$row['video2_path']." </td>
<td> ".$row['video3_path']." </td>
<td> ".$row['video4_path']." </td>
</tr>";
}
echo "<input type= 'submit' value='submit' >";
echo "</form>";
}
?>
</table>
</div>
搜索.php
<div style="overflow-x:auto;">
<table id="test_data">
<tr>
<th> Test ID </th>
<th> Path </th>
<th> Video 1 Path </th>
<th> Video 2 Path</th>
<th> Video 3 Path</th>
<th> Video 4 Path</th>
</tr>
<?php
if (isset($_POST['checkbox_id'])) {
$checkbox_id = $_POST['checkbox_id'];
$sql= "SELECT * FROM test_data WHERE test_id IN $checkbox_id";
$result = mysqli_query($conn, $sql);
$queryResults = mysqli_num_rows($result);
if ($queryResults > 0) {
while ($row = mysqli_fetch_assoc($result)){
$field1name = $row["test_id"];
$field2name = $row["path"];
$field3name = $row["video1_path"];
$field4name = $row["video2_path"];
$field5name = $row["video3_path"];
$field6name = $row["video4_path"];
echo "<tr>
<td> ".$field1name." </td>
<td> ".$field2name." </td>
<td> ".$field3name." </td>
<td> ".$field4name." </td>
<td> ".$field5name." </td>
<td> ".$field6name." </td>
</tr>";
}
}else {
echo "There are no results matching your search";
}
}
?>
</table>
</div>
会创建复选框,但单击“提交”按钮时,不会显示任何数据。有什么帮助吗?
1条答案
按热度按时间vktxenjb1#
您的复选框值现在为“$请更正复选框中的值,但不是真正的id