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

  • 写回答

1条回答 默认 最新

  • dpv21589 2019-05-23 00:02
    关注

    In your query, you are comparing

    '$LongYear' = ".$LongYear
    

    this will always succeed. You should be comparing the year from the value of the column instead:

    YEAR(QuoteDate) = ".$LongYear
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况