Im trying to make a code generator for my table
Here's my model :
public function buat_kode() {
$this->db->table('RIGHT(proses_cutting.kode_packing_list,6) as kode', FALSE);
$this->builder()->orderBy('kode_packing_list','DESC');
$this->builder()->limit(1);
$query = $this->db->table('proses_cutting'); //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, 6, "0", STR_PAD_LEFT); // angka 4 menunjukkan jumlah digit angka 0
$kodejadi = "PLIK059".$kodemax; // hasilnya ODJ-9921-0001 dst.
return $kodejadi;
}
controller :
public function create()
{
session();
$data = [
'main' => 'prosescutting/create',
'validation' => \Config\Services::validation(),
'title' => 'Form Tambah Proses Cutting',
'kodeunik' => $this->pcuttingModel->buat_kode(),
'kode_packing_list' => $kodePackingSekarang,
];
return view('template/template', $data);
}
and my table : Table
What im trying to do is make a generator for kode_packing_list for each item of nama_barang so when i input another Renata Blouse it will automatically fill with PLIK059000007
But when I tried to run it, it show me these errors:
Error Call to undefined method CodeIgniter\Database\MySQLi\Builder::num_rows() APPPATH\Models\PcuttingModel.php at line 33
and the line 33 is
if ($query->num_rows() <> 0){