gpt4 book ai didi

PHP 字符串操作和 SQL 查询

转载 作者:行者123 更新时间:2023-11-29 22:04:10 26 4
gpt4 key购买 nike

您好,我还是一个 php 编程初学者,我的项目的功能之一是检查数据库中是否存在时间表。无论如何,我的问题是我创建字符串查询的方式,我不确定字符串在语法方面是否正确,但查询是正确的并在 phpmyadmin MySQL GUI 中进行了测试。

$start_time = $_POST['Time-In'];
$end_time = $_POST['Time-Out'];
$procedure_date = $_POST['txbDateofProcedure'];

$DateStartTime = $procedure_date." ".$start_time;
$DateEndTime = $procedure_date." ".$end_time;

//Not sure but i think that the $Check-Schedule php syntax is incorrect
$Check_Schedule = "select * from appointment_dim where dentist_id = '$dentist_id'".
"and (CONCAT(appoint_date, ,appoint_timein) between '$DateStartTime' and '$DateEndTime')".
"OR (CONCAT(appoint_date, ,appoint_timeout) between '$DateStartTime' and '$DateEndTime')";

$result_schedule = mysql_query($Check_Schedule,$con);
if(!$result_schedule)
{
trigger_error("Cannot located database".mysql_error());
die();
}
if(mysql_num_rows($result_schedule) > 0)
{
$SchedErrMesg = "The time you requested is already take try again.";
echo"<script type='text/javascript'>alert('$SchedErrMesg');</script>";
die();
}

最佳答案

如果您希望 appoint_dateappoint_time* 之间的分隔符为空格,您应该这样做:

CONCAT(appoint_date, ' ', appoint_timein)

但不是这个:

CONCAT(appoint_date, , appoint_timein)

我相信你想要这样的逻辑

"dentist_id = x AND (timeBetween1 OR timeBetween2)"

但不是你写的:

"(dentist_id = x AND timeBetween1) OR timeBetween2"

所以试试这个:

$Check_Schedule = "
SELECT * FROM appointment_dim
WHERE
dentist_id = '$dentist_id'
AND (
(CONCAT(appoint_date, ' ', appoint_timein) BETWEEN '$DateStartTime' AND '$DateEndTime')
OR (CONCAT(appoint_date, ' ', appoint_timeout) BETWEEN '$DateStartTime' AND '$DateEndTime')
)
";

关于PHP 字符串操作和 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32324688/

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