我正在尝试编写一些PHP代码,以便当用户输入报价时,应用程序查看报价表,计算该年提出的报价数量,然后在计数中加1,最终结果是提供当年的唯一且连续的报价编号。格式应为Q / YY /序号
//Insert New Q Reference
//set standards
$time=strtotime($values['QuoteDate']);
$LongYear=date("Y",$time);
$ShortYear=date("y",$time);
//Get current number quotes for the year which quote was issued
global $dal;
$dal_table = $dal->Table("quotations");
if ($values["QuoteDate"])
{
$rstmp = CustomQuery("select count(*) as count1 from quotations where '$LongYear' = ".$LongYear);
$datatmp = db_fetch_array($rstmp);
$count_value = 0;
if ($datatmp["count1"]) $count_value = $datatmp["count1"];
$values['QuoteReference'] = 'Q/'.$ShortYear.'/'.str_pad(($count_value+1), 4, '0', STR_PAD_LEFT);
}
我遇到的问题是代码仅返回总顺序号+ 1,并且没有考虑年份的计数!
请参见以下屏幕截图,2018年应为Q / 18/0001
答案 0 :(得分:0)
在查询中,您正在比较
'$LongYear' = ".$LongYear
这将永远成功。您应该从该列的值中比较年份:
YEAR(QuoteDate) = ".$LongYear