我发送一个条目,其中有timeA和timeB,并希望如果那个时间已经在表中,我的条目不应该被插入


Am sending an entry in which there is timeA and timeB and want that if that time is already in the table my entry should not be inserted

我正在发送一个调整表,其中有2个时间时间A和时间B它们都以varchar的形式存储在表中我想,如果调整已经在表之间的时间,所以用户不能输入任何其他条目请帮助我新的mysqli和php

$required_request = mysql_query("select * from swaps_prac_wfm where csrid = '$_SESSION[userid]' and (start_time<='$a' or start_time>='$b') ");
$rows_require = mysqli_num_rows($required_request); 
if (!$rows_require){ 
    insert
} 
else { 
    you already have adjustment between that time.
}

您必须将VARCHAR列更改为date/datetime类型,因为比较VARCHARs会返回不正确的结果。

你说你需要检查TimeATimeB之间是否有一个条目,那么你应该用AND替换查询中的OR

剩下的代码就可以了。我只是做了一些修改:

$required_request = mysql_query("select * from swaps_prac_wfm where csrid = '$_SESSION[userid]' and (start_time<='$a' AND start_time>='$b') ");
$rows_require = mysqli_num_rows($required_request);
if ((int) $rows_require === 0)
{
    insert
} else{
    you already have adjustment between that time.
}