代码实现:
$today = date ( "Ymd", time () );//获取系统当前时间 $query = "select max(Id) as maxId from info where Id like '$today%'";//在数据库中查询当日是否已经有编号产生,如果有返回最大值的那一条 $result = $db->query ( $query ); $num_result = $result->num_rows; $row = $result->fetch_assoc ();//执行数据库查询 if ($row[Id] == 0) //如果返回的结果为0,则表示当日没有生成,则生成当日第一个编号 { $requestId = str_pad ( $today, 12, 0, STR_PAD_RIGHT ) + 1; } else //否则直接在当日的上一个编号上增加1 { $Id = $row ['maxId'] + 1; }
相关函数解释:
str_pad:把字符串填充为指定的长度。str_pad(string,length,pad_string,pad_type)
STR_PAD_RIGHT:填充到字符串的右侧。这是默认的
http://www.savh.cn/thread-220.htm
转载请注明:Savh.Cn 发表