Php 每月自动重置的参考编号
我正在生成参考编号REF-082013-001(REF-mmyyyy-001),并增加每个条目的最后一部分。第一条记录参考-082013-001,第二条记录参考-082013-002,依此类推 我的问题是如何通过php为每个新月份重置最后一个数字。假设2013年9月,我希望它是REF-09-2013-001,并自动递增到9月底,然后在11月再次重置它 在php中有没有实现这一点的方法。非常感谢你的帮助。多谢各位 更新Php 每月自动重置的参考编号,php,mysql,Php,Mysql,我正在生成参考编号REF-082013-001(REF-mmyyyy-001),并增加每个条目的最后一部分。第一条记录参考-082013-001,第二条记录参考-082013-002,依此类推 我的问题是如何通过php为每个新月份重置最后一个数字。假设2013年9月,我希望它是REF-09-2013-001,并自动递增到9月底,然后在11月再次重置它 在php中有没有实现这一点的方法。非常感谢你的帮助。多谢各位 更新 目前,'REF-'.date('m-Y').$maxnumberfromdb位
目前,'REF-'.date('m-Y').$maxnumberfromdb位于名为reference\u no的单列中,现在考虑将mm-yyyy参考1和最后一个数字分别存储在参考2中,并在每月的第一天启动参考2 您可以使用一个表,一个自动递增字段来处理参考号的最后一部分,一个日期/时间字段来跟踪上次重置的时间
CREATE TABLE track_reference
ref_number INT(11) AUTO_INCREMENT,
last_reset DATETIME;
然后用PHP编写一个函数来获取一个新的引用号,它(伪代码):
if(月(时间())>MONTH(上次重置)){
将参考号重置为0(使用ALTER TABLE);
}
在$variable中选择(参考号);
返回'REF\\$变量;
}
这很艰难,但你明白了。我还希望年出现在月之前,以便于以后按参考号排序。这是我重置计数器和更新上次重置的代码,这对我有效
This is my code for reset counter and update last_reset, this is effective for me
<pre>
$date2 = new DateTime("now", new DateTimeZone('America/New_York') );
$month_end = strtotime('last day of this month', time());
$count = $data['sim_tarif_count'];
$date3=$date2->format('Y-m-d');
foreach ( $count as $r2 ){
$counts[] = $r2['count'];
$last_reset[] = $r2['last_reset'];}
$paddedNum = sprintf("%04d", $counts[0]);
$reg_id = 'SEQ'.$date2->format('Ymd').$paddedNum;
echo " ";
echo date('j', $month_end);
$counter = $counts[0]+1;
//for reset
if($date2->format('Y-m') > $last_reset[0])
{
$counter = 0;
$counting_update=$this->docs_model->update_time_counter($counter,$date3);
echo $counter = 0;
} else
{
$counting_update=$this->docs_model->update_time_count($counter);
}
</pre>
$date2=新日期时间(“现在”,新日期时区(“美国/纽约”);
$month_end=strotime('本月最后一天',time());
$count=$data['sim_tarif_count'];
$date3=$date2->格式('Y-m-d');
foreach($r2){
$counts[]=$r2['count'];
$last_reset[]=$r2['last_reset']];}
$paddedNum=sprintf(“%04d”,$counts[0]);
$reg_id='SEQ'.$date2->format('Ymd')。$paddedNum;
回声“;
回音日期('j',$月底);
$counter=$counts[0]+1;
//重置
如果($date2->format('Y-m')>$last\u reset[0])
{
$counter=0;
$counting\u update=$this->docs\u model->update\u time\u counter($counter,$date3);
echo$计数器=0;
}否则
{
$counting\u update=$this->docs\u model->update\u time\u count($counter);
}
您是如何存储分配的参考号的?还没有,我想分别存储mm yyy和最后一个编号,并在每个月的第一天重新开始。更新了问题。谢谢你你的储藏室是什么?MySQL?@Wouter Huysentruit是的,MySQL
This is my code for reset counter and update last_reset, this is effective for me
<pre>
$date2 = new DateTime("now", new DateTimeZone('America/New_York') );
$month_end = strtotime('last day of this month', time());
$count = $data['sim_tarif_count'];
$date3=$date2->format('Y-m-d');
foreach ( $count as $r2 ){
$counts[] = $r2['count'];
$last_reset[] = $r2['last_reset'];}
$paddedNum = sprintf("%04d", $counts[0]);
$reg_id = 'SEQ'.$date2->format('Ymd').$paddedNum;
echo " ";
echo date('j', $month_end);
$counter = $counts[0]+1;
//for reset
if($date2->format('Y-m') > $last_reset[0])
{
$counter = 0;
$counting_update=$this->docs_model->update_time_counter($counter,$date3);
echo $counter = 0;
} else
{
$counting_update=$this->docs_model->update_time_count($counter);
}
</pre>