I just want to display my database in a table and inside the table have a checkbox for each row. The user will have the option to check one or more boxes, in which then the user will hit a submit button and view the selected data in another page. The following is the code that I tried.
index.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>
search.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'])) {
$search = mysqli_real_escape_string($conn,$_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>
The checkboxes are created but when the submit button is clicked no data is shown. Any help?
Aucun commentaire:
Enregistrer un commentaire