在5个月内应仅将3个用户插入数据库 [英] only 3 users shoud be inserted into the database within a timespan of 5 months
问题描述
进行一些我先前删除的更改后,重新发布该问题. 我尽力了,但我不知道该怎么实现.
Reposting the question after making some changes which i deleted earlier. I tried hard but I could not figure out how to achieve it.
我有一张桌子fw_invitations
I have a table fw_invitations
ID OFFICEID Consultationdate
------------------------------
1 1 16-06-2013
2 1 16-06-2013
3 1 16-06-2013
4 1 17-08-2014
5 1 17-08-2014
$consultationdate
包含用户输入的日期.
$consultationdate
contains the date entered by the user.
$invcount="Select count(*) as noofinv,
Datediff('$consultationdate',max(consultationdate)) as datediffinv
from fw_invitations where OFFICEID = 1";
$db->setQuery($invcount);
$invcounts=$db->loadAssoclist();
$noofinv=$invcounts[0]['noofinv'];
$datediffinv=abs($invcounts[0]['datediffinv']);
if($noofinv >3 && $datediffinv <150)
{
$error_message="Het maximale ";
}
我也在尝试这样做,但是下面的查询总是导致0
I am also trying this but the below query always resulting in 0
$invcount="Select count(*) as noofinv from fw_invitations
where consultationdate between
DATE_SUB($consultationdate,INTERVAL 150 DAY) and
DATE_ADD($consultationdate,INTERVAL 150 DAY) from fw_invitations where OFFICEID = 1";
我想做的是,如果datediff超过150(5个月),则表中插入的用户数不能超过3.
what I want to do is that not more than 3 user should be inserted into the table if the datediff is more than 150(5 months).
除非输入的时间间隔过长,否则上面的查询无法正常运行.由于我正在使用max(consultationdate)
,因此上表的最大日期为2014年8月17日,因此无法验证用户再次输入日期16-06-2013的情况.
My above query was working perfectly unless I entered the date with a long interval. Since I am using max(consultationdate)
so max date for the above table will be 17-08-2014, it will not validate the case in which a user again enters the date 16-06-2013.
简而言之,我想做的是在任何情况下,在5个月的时间内都应仅将3个用户插入数据库.
推荐答案
在更正了它的魅力之后,我错过了$ consultationdate中的单引号,这就是为什么它每次产生0的原因.
i missed the single quotes in the $consultationdate thats ahy it was resulting 0 everytime,after correcting that its working like a charm .
$invcount="Select count(*) as noofinv from fw_invitations
where consultationdate between
DATE_SUB('$consultationdate',INTERVAL 150 DAY) and
DATE_ADD('$consultationdate',INTERVAL 150 DAY) from fw_invitations where OFFICEID = 1";
这篇关于在5个月内应仅将3个用户插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!