I have a table on one page "view-truck-check.php" that displays the past vehicle checks that were completed on a specific date. In the same row that lists the submission date is also a view button that will pull up another page "view-submitted-check.php" that shows a table with ONLY the checks that were completed on the date listed on the first page table.
This is the 1st page This is the first table ("view-truck-check.php") That displays the previously submitted checks and what dates they were completed on.
This is the code for that table
<?php>
$checkssql = " SELECT * FROM $appname2 GROUP BY date ORDER BY date DESC";
$checksqry = mysqli_query($conn, $checkssql);
<?>
<form name="submittedchecks" id="submittedchecks" method="POST" action="view-submitted-check.php">
<div class="table-responsive text-nowrap">
<table class="table" >
<thead>
<tr>
<th>Date</th>
<th>Submitted By</th>
</tr>
</thead>
<tbody class="table-border-bottom-0">
<?php while ($checks = mysqli_fetch_array($checksqry)) {{
echo '<input type=hidden name="checkid[]" value='. $checks['date']. '>';
echo '<input type="text" name="appname" id="appname" readonly value="'.$appname2.'" hidden="hidden">';
echo '<tr>';
echo '<td style="width: 20%"> <input type="text" value="'.$checks['date'].'" name="date[]" style="border: none" readonly></td>';
echo '<td>'.$checks['submitted_by'].'</td>';
echo "<td> <button class='btn btn-info' type='submit' name='submitview' id='submitview'>View</button> </td> " ;}
echo'</tr>'; }?>
</table>
</div>
</form>
When I click on view, it shows every single check ever completed, rather than ONLY the date listed. I only want to see the checks that were completed on the date listed and only those.
This is what my current code is doing. Its showing all checks.
This is the code for the 2nd page "view-submitted-check.php"
<div class="card" style="width: 85%;">
<h5 class="card-header"></h5>
<div class="table-responsive text-nowrap">
<?php
$appname = $_POST['appname'];
if (!$appname == ($appname)) {
die("Invalid app name!");
}
$stmt = mysqli_prepare($conn, "SELECT * FROM $appname WHERE date = ? ORDER BY id");
mysqli_stmt_bind_param($stmt, "s", $date);
foreach ($_POST['date'] as $date){
mysqli_stmt_execute($stmt);
$viewresult = mysqli_stmt_get_result($stmt);
?>
<table class="table" >
<h3><?php echo $date?></h3>
<thead>
<tr>
<th>Check Name</th>
<th>Status</th>
<th>Comment</th>
</tr>
</thead>
<tbody class="table-border-bottom-0">
<?php while ($checkview = mysqli_fetch_array($viewresult)) {
echo '<tr>';
echo '<td>' .$checkview['check_name']. '</td>';
if($checkview['status']=='Pass'){ echo "<td> <label class='btn rounded-pill btn-success'>Pass</label> </td> " ;}
elseif($checkview['status']=='Warning'){ echo "<td> <label class='btn rounded-pill btn-warning'>Warning</label> </td> " ;}
elseif($checkview['status']=='Fail'){ echo "<td> <label class='btn rounded-pill btn-danger'>Fail</label> </td> " ;}
echo '<td>' .$checkview['comment']. '</td>';
echo'</tr>';
}
?>
</tbody>
</table>
<?php
}?>
</div>
</div>