⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Generate code from date



Aldo Christian
  • profile picture
  • Member

Posted 06 June 2013 - 02:15 AM

I want generate unique code (primary key) from date and transaction sequence number.

So example. today is 06/05/2013 and its first transaction.

php/grocery will create 201305060001

 

But, i'm stuck, dont know where to start???

 

any idea???


PunkMaster
  • profile picture
  • Member

Posted 06 June 2013 - 08:50 AM

use callback_after_insert and callback_after_update 

 

suppose this is your callback function 

 

function generate_code($post_array, $primary_key){

 

$id = $primary_key;

$date = date('y/m/d')

$date = str_replace('/', '', $date);

$code=$date

$code.=id

$data = array('ur_field'=>$code);

$this->db->where('ur_table_field_id', $id);

$this->db->update('ur_table', $data)

return true;

 

}