Last active
May 13, 2017 08:34
-
-
Save bigkiandi/d9567ef5ddf29e3780c3c416b7f54f53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Model_user extends CI_Model { | |
var $db; | |
var $table = "user"; | |
public function buat_kode() { | |
$this->db->select('RIGHT(user.id_odojers,4) as kode', FALSE); | |
$this->db->order_by('id_odojers','DESC'); | |
$this->db->limit(1); | |
$query = $this->db->get('user'); //cek dulu apakah ada sudah ada kode di tabel. | |
if($query->num_rows() <> 0){ | |
//jika kode ternyata sudah ada. | |
$data = $query->row(); | |
$kode = intval($data->kode) + 1; | |
} | |
else { | |
//jika kode belum ada | |
$kode = 1; | |
} | |
$kodemax = str_pad($kode, 4, "0", STR_PAD_LEFT); // angka 4 menunjukkan jumlah digit angka 0 | |
$kodejadi = "ODJ-9921-".$kodemax; // hasilnya ODJ-9921-0001 dst. | |
return $kodejadi; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment