自动生成代码/文本

时间:2017-08-24 07:51:22

标签: javascript php jquery html5 pdo

我正在开发一个适用于票务技术的项目,我需要生成一个生成代码的字段,可以插入到数据库中。

并且代码具有指定的表单,包含3或4个字母,日期和自动递增的数字,如:

PRUC-120717-0001 - > PRUC-120717-0002

OR

PRUC-12/07/17-0001 - > PRUC-12/07/17-0002

3 个答案:

答案 0 :(得分:0)

我创建了一个这样的系统。

以下是代码:

<?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和auto递增1

实施例。在数据库中我们有PRUC-12/07 / 17-0001下一个插入将是PRUC-12/07 / 17-0002。

答案 1 :(得分:0)

enter image description here

单击代码的链接 www.uploadfiles.io/ool9o

答案 2 :(得分:0)

试试这个

 function getLoadCode($currentdate) {
        $productid = str_pad($load_id, 5, '0', STR_PAD_LEFT);
        $productid = "PRUC".$currentdate;
        return $productid;
    }
相关问题