gpt4 book ai didi

PHP 检查 MySQL 数据库日期时间

转载 作者:行者123 更新时间:2023-11-29 20:54:06 25 4
gpt4 key购买 nike

我正在开发一个项目,该项目允许用户将预订分配给出租车,但只有在请求的时间预计至少在 2 小时内时,该值才会显示。

这里是存储php/sql。

<?php

$query = "INSERT INTO Taxi(fname, lname, number, unit, snumber, sname, suburb, dsuburb, dt, status) VALUES('{$fname}','{$lname}','{$contact}','{$unit}','{$snumber}','{$sname}','{$suburb}','{$dsuburb}','{$dt}','{$status}')";
if (mysqli_query($conn, $query)) {


$date = date_create($dt);
$dateFormatted = date_format($date, 'g:ia \o\n d/m/y');
echo "Thank you! Your booking reference number is " . mysqli_insert_id($conn) . " you will be picked up in front of your provided address at " . date_format($date, 'g:ia \o\n l jS F Y') . ".";

} else if (!mysqli_query($conn, $query)) {
echo mysqli_error($conn);
}
mysqli_close($conn);


?>

这是用于分配出租车的 PHP,现在要在表中显示,当时间将在未来 2 小时或更长时间时,它应该只显示未分配表中的值。如何进行时间比较?

<?php

require_once ("settings.php");
$conn = @mysqli_connect($host, $user, $pswd)
or die('Failed to connect to server');

@mysqli_select_db($conn, $dbnm)
or die('Database not available');

$query = "SELECT id, fname, lname, number, unit, snumber, sname, suburb, dsuburb, dt, status FROM taxi WHERE status = 'unassigned'";

$results = mysqli_query($conn, $query);

echo "<table width='100%' border ='1'>";
echo "<tr><th>Booking Id</th><th>First<br>Name</th><th>Last<br>Name</th><th>Contact</th><th>Unit<br>Number</th><th>Street<br>Number</th><th>Street<br>Name</th><th>Suburb</th><th>Destination<br>Suburb</th><th>Date/Time</th><th>Status</th></tr>";

while($row = mysqli_fetch_assoc($results)) {
echo "<tr>";
echo "<td> {$row['id']}</td>";
echo "<td> {$row['fname']}</td>";
echo "<td> {$row['lname']}</td>";
echo "<td> {$row['number']}</td>";
echo "<td> {$row['unit']}</td>";
echo "<td> {$row['sname']}</td>";
echo "<td> {$row['snumber']}</td>";
echo "<td> {$row['suburb']}</td>";
echo "<td> {$row['dsuburb']}</td>";
echo "<td> {$row['dt']}</td>";
echo "<td> {$row['status']}</td>";
echo "</tr>";
}

$query = "SELECT id, fname, lname, number, unit, snumber, sname, suburb, dsuburb, dt, status FROM taxi WHERE status = 'assigned'";

$results = mysqli_query($conn, $query);

echo "<table width='100%' border ='1'>";
echo "<tr><th>Booking Id</th><th>First<br>Name</th><th>Last<br>Name</th><th>Contact</th><th>Unit<br>Number</th><th>Street<br>Number</th><th>Street<br>Name</th><th>Suburb</th><th>Destination<br>Suburb</th><th>Date/Time</th><th>Status</th></tr>";

while($row = mysqli_fetch_assoc($results)) {
echo "<tr>";
echo "<td> {$row['id']}</td>";
echo "<td> {$row['fname']}</td>";
echo "<td> {$row['lname']}</td>";
echo "<td> {$row['number']}</td>";
echo "<td> {$row['unit']}</td>";
echo "<td> {$row['sname']}</td>";
echo "<td> {$row['snumber']}</td>";
echo "<td> {$row['suburb']}</td>";
echo "<td> {$row['dsuburb']}</td>";
echo "<td> {$row['dt']}</td>";
echo "<td> {$row['status']}</td>";
echo "</tr>";
}
echo "<br>";
mysqli_free_result($results);
mysqli_close($conn);
?>

最佳答案

类似...

$requestedDateTime = $_POST["datetime"];
$interval = 2;
$endDateTime = date("$requestedDateTime", strtotime("+{$interval} hours"));

if($endDateTime >= $requestedDateTime) {
//your code here to accept the booking
}
else {
//error msg time is too short
}

关于PHP 检查 MySQL 数据库日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37771160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com