I have a page that lays out tasks for a user. I am trying to figure out how to structure the logic so that the user can click a checkbox (first table column) and it update the database row in which the foreach row came from. I know what I gotta do, but not sure how to do it. Can someone be so kind to help me out.
If Pending
and checkbox is checked it will update the DB status to Completed
If Overdue
and checkbox is checked it will update the DB status to Completed
If Completed
it will disable the checkbox for that specific task.
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">Pending Tasks</h3>
<div class="box-tools pull-right">
</div>
</div>
<div class="box-body">
<table class="table table-hover table-striped">
<tbody>
<?php
$TasksCategory = 'Task';
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM tbl_name WHERE Category = ? AND Company_Hash = ? AND Company_Name = ? ORDER BY Due_Date DESC";
$q = $pdo->prepare($sql);
$q->execute(array($TasksCategory,$Company_Hash,$Company_Name));
$Tasks = $q->fetchAll(PDO::FETCH_ASSOC);
Database::disconnect();
if ($q->rowCount() > 0) {
?>
<th>Checkbox</th>
<th>Task Title</th>
<th>Task Details</th>
<th>Status</th>
<th>Due Date</th>
<th>Responsible</th>
<th>View Client</th>
<?php
foreach($Tasks as $Task) {
?>
<tr>
<td><input type='checkbox'></td>
<td><?php echo $Task['Title']; ?></td>
<td><?php echo $Task['Details']; ?></td>
<td><?php
$TaskStatus = $Task['Status'];
if ($TaskStatus === 'Pending') { $Pending = "<small><button style='width:70px;' class='btn btn-block btn-info btn-xs'>Pending</button></small>"; echo $Pending; }
elseif ($TaskStatus === 'Completed') { $Completed = "<small><button style='width:70px;' class='btn btn-block btn-success btn-xs'>Completed</button></small>"; echo $Completed; }
elseif ($TaskStatus === 'Overdue') { $Overdue = "<small><button style='width:70px;' class='btn btn-block btn-warning btn-xs'>Overdue</button></small>"; echo $Overdue; }
?></td>
<td><?php echo $Task['Due_Date']; ?></td>
<td><small><?php echo $Task['Responsible'];?></small></td>
<td><small><?php echo'<a href="page.php?api='.$Task['API'].'&id='.$Task['id'].'&ch='.$Task['Company_Hash'].'&rid='.$Task['RecordLocatorID'].'&pp=tasksdash"><small><button type="button" class="btn btn-warning"><i class="fa fa-eye"></i></button></small></a>'; ?></small></td>
</tr>
<?php
}
}
else {
echo '<tr><center><h4>You currently have no tasks</h4></center><tr>';
}
?>
</tbody>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div>
Aucun commentaire:
Enregistrer un commentaire