CodeIgniter Forums

Full Version: how to generate Custom id in codeigniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
$cc = $this->db->count_all('job_card');
$coun = str_pad($cc,4,STR_PAD_LEFT);
$id = "JI"."-";
$d = date('y') ;
$mnth = date("m");
$customid = $id.$d.$mnth.$coun;
Help me: I am generating "JI-18051000" This id. But i need "JI-18050001" this id.
(05-29-2018, 09:49 PM)azmath Wrote: [ -> ]
Code:
$cc = $this->db->count_all('job_card');
$coun = str_pad($cc,4,STR_PAD_LEFT);
$id = "JI"."-";
$d = date('y') ;
$mnth = date("m");
$customid = $id.$d.$mnth.$coun;
Help me: I am generating "JI-18051000" This id. But i need "JI-18050001" this id.

Do you have id in job_card table? if so get 
PHP Code:
$result $this->db->select('max("id") as max_id'false)->from('job_card')->get(); $coun $result['max_id'] + 1

 and if your generated id is final value just generate new column in your job_card table and record it there so that you won't regenarate every time.
You can also take look at "composite fields" for your db
$cc = $this->db->count_all('gbp')+1;
$coun = str_pad($cc,4,STR_PAD_LEFT);
$coo=strrev($coun);
$id = "GBP"."-";
$d = date('y') ;
$mnth = date("m")."-";
$product_id = $id.$d.$mnth.$coo;
echo $product_id;