duanmu1736
2019-05-22 23:56
浏览 69
已采纳

获取一年的记录数

I am trying to write some PHP code so that when a user enters a quote, the application looks at the quote table, counts how many quotes have been raised for that year, then adds 1 to the count, the end result is to provide a unique and sequential quote number for that year. The format is supposed to be Q/YY/sequential number

//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);

        }

The problem i am having is that the code is just returning the total sequential number + 1 and it is not taking into account the count of the year!

See the following screenshot, the 2018 is supposed to be Q/18/0001

图片转代码服务由CSDN问答提供 功能建议

我正在尝试编写一些PHP代码,以便当用户输入引号时,应用程序会查看引用表 ,计算当年提出的报价数量,然后将计数加1,最终结果是为该年度提供唯一且连续的报价编号。 格式应为Q / YY /序号 <前> //插入新Q参考 //设置标准 $ time = strtotime($ values ['QuoteDate ']); $ LongYear = date(“Y”,$ time); $ ShortYear = date(“y”,$ time); //获取报价年份的当前数字报价 发布 全球$ dal; $ dal_table = $ dal-&gt;表格(“报价”); if($ values [“QuoteDate”]) { $ rstmp = CustomQuery(“select count(*)as quot1 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 \ n

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题