I have a table nested within a form that looks as follows:
The "leave_request_processor.php" file that receives the post request from the above file then reads as follows:
$approved = "Approved";
$rejected = "Rejected";
foreach($all_leave_ids as $leave_id){
if(isset($_POST["approve"])){
$strQuery2 = "UPDATE leave_applications SET status = '$approved' WHERE application_id = '$leave_id' ";
$result2 = mysqli_query($connection,$strQuery2) or Exit ("Query execution failed");
mysqli_close($connection);
header("Location: leave_check.php"); /* Redirect browser */
exit();
}
else if (isset($_POST["reject"])){
$strQuery3 = "UPDATE leave_applications SET status = '$rejected' WHERE application_id = '$leave_id' ";
$result3 = mysqli_query($connection,$strQuery3) or Exit ("Query execution failed");
mysqli_close($connection);
header("Location: leave_check.php"); /* Redirect browser */
exit();
}
}
The code works but starting with the first row (whichever rows' button you click) in descending order then the page reloads and you're left with the pending requests.
I bet there's a way you can code it (I'm thinking JavaScript) so that if I click "Approve" on row 23 it acts on that row. Anyone know how I can achieve this?
@Rasclatt I tried this out. Is this what you had in mind? Didn't work though.
$strQuery = "SELECT * from leave_applications WHERE status = 'Pending' ";
$result = mysqli_query($connection, $strQuery) or Exit("Query execution failed");
if($result->num_rows>0){
// output data of each row
echo "<table class='pure-table pure-table-bordered'>
<thead>
<tr>
<th>Application ID</th>
<th>Student ID</th>
<th>Email</th>
<th>Days Requested</th>
<th>Status</th>
<th colspan='2'>ACTION TO TAKE</th>
</tr>
</thead>";
while($row = $result->fetch_assoc()){
array_push($allleaveids,$row["application_id"]);
echo
"<form action='leave_request_processor.php' method='post' target='_self' name='leave_check' class='pure-form pure-form-aligned'>
<tr>
<td>".$row["application_id"]."</td>
<td>".$row["student_id"]."</td>
<td>".$row["email"]."</td>
<td>".$row["days_requested"]."</td>
<td>".$row["status"]."</td>
<td><button class='button-success pure-button' name='approve' type='submit'>Approve</button></td>
<td><button class='button-error pure-button' name='reject' type='submit'>Reject</button></td>
</tr>
</form>";
echo "</table>";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.