我正在做一个关于票务技术的项目,我需要生成一个生成代码的字段,这个字段可以插入到DB中。
代码中指定的表单包含3个或4个字母、日期和自动递增的数字,如:
PRUC-120717-0001 -> PRUC-120717-0002
或
PRUC-12/07/17-0001 -> PRUC-12/07/17-0002
发布于 2017-08-24 08:24:07
我创造了这样一个系统。
以下是代码:
<?php
$proc = "PRUC";
$date = date('m-d-Y');
$sth = $conn->prepare("SELECT count(*) as total from mytable where SUBSTRING(produc, 1, 6)='$proc'");
$sth->execute();
$number_of_rows = $sth->fetchColumn();
if($number_of_rows<=0){
$number_of_rows;
}
$total = $number_of_rows + 1;
echo $proc.$date.sprintf('%04d', $total);
?>在查询中,它将计算多少pruc和自动增量1。
例如。在数据库中,我们有PRUC-12/07/17-0001,下一个插入将是PRUC-12/07/17-0002。
发布于 2017-08-24 08:35:27

单击代码Www.upadfiles.io/ool9o的链接
发布于 2017-08-24 08:35:39
尝尝这个
function getLoadCode($currentdate) {
$productid = str_pad($load_id, 5, '0', STR_PAD_LEFT);
$productid = "PRUC".$currentdate;
return $productid;
}https://stackoverflow.com/questions/45855907
复制相似问题