user_reservation.php
<thead>
<tr>
<th scope="col">Number of Guest</th>
<th scope="col">Type of Service</th>
<th scope="col">Date</th>
<th scope="col">Time</th>
<th scope="col">Status</th>
<th scope="col">Edit</th>
</tr>
</thead>
<tbody>
<?php
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['no_guest']; ?></td>
<td><?php echo $row['type_service']; ?></td>
<td><?php echo $row['datepicker']; ?></td>
<td><?php echo $row['t_time']; ?></td>
<td><?php echo $service['status']; ?></td>
<td><a href="editform.php?id=<?php echo $row['id']; ?>"> edit </a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<b>STATUS</b><br>
<?php
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<!--<td><?php //echo $row['datepicker']; ?></td>-->
<?php
$today = date("Y-m-d H:i:s");
$startdate = $row['datepicker'];
$offset = strtotime("+2 day");
$enddate = date($startdate, $offset);
$today_date = new DateTime($today);
$expiry_date = new DateTime($enddate);
$status = ($expiry_date < $today_date) ? 'Expired' : 'Active' ;
$result = $dbs->prepare("UPDATE Customers SET status = :status WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->bindParam(':status', $status);
$result->execute();
?>
<?php
}
?>
这是我在user_reservation上的完整代码。我想在我的admin_reservation上想要获取我的状态数据库中的内容。但正如您所见,我仍然无法在我的数据库中插入状态数据
答案 0 :(得分:0)
使用phpMyAdmin在表'service_info'中添加列'status',例如, 然后在你的时间验证:
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<?php
$today = date("Y-m-d H:i:s");
$startdate = $row['datepicker'];
$offset = strtotime("+2 day");
$enddate = date($startdate, $offset);
$today_date = new DateTime($today);
$expiry_date = new DateTime($enddate);
$status = ($expiry_date < $today_date) ? 'Expired' : 'Active' ;
$result = $dbs->prepare("UPDATE Customers SET status = :status WHERE id = :id");
$result->execute(array(':status'=>$status, ':id'=>$_SESSION['id']));
然后在你的表中,只输出状态列:
<tr class="record">
<td><?php echo $customers[$key]['firstname'];?></td>
<td><?php echo $service['no_guest']; ?></td>
<td><?php echo $service['type_service']; ?></td>
<td><?php echo $service['datepicker']; ?></td>
<td><?php echo $service['t_time']; ?></td>
<td><?php echo $service['status']; ?></td>