douque9815 2018-08-03 07:22
浏览 46
已采纳

在codeigniter中生成11位序列号

Here is my model function for generate serial numbers

public function getmax($field_name,$table_name){

        $this->db->select_max($field_name);
        $res1 = $this->db->get($table_name);
        if ($res1->num_rows() > 0) {
            $res2 = $res1->result_array();                  
        }
        $max = $res2[0][$field_name];
        if($max == NULL) return 1; else return $max+1;
    }   

Here is my controller Function

$CardNo = $this->general_model->getmax('card_number','digicardusers');

I want to set serial numbers starting from 00000000001.How to change the code to get 11 digit serial numbers.Any one please help

  • 写回答

2条回答 默认 最新

  • douchongzhang9267 2018-08-03 07:34
    关注

    Presuming your just looking for the 0'padding, use sprintf()

    <?php
    for ($i = 1; $i < 25; $i++) {
        echo sprintf("%'.011d", $i).PHP_EOL;
    }
    

    https://3v4l.org/UanaJ

    00000000001
    00000000002
    00000000003
    00000000004
    00000000005
    00000000006
    00000000007
    00000000008
    00000000009
    00000000010
    00000000011
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化