I have 3 tables, tbl_reservasi
, tbl_ruangan
, and user
.
I want to update my tbl_ruangan.status
from Tersedia
to Tidak Tersedia
.
Here's my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Reservation extends MY_Controller {
public function index()
{
$this->push_breadcrumb('Reservation', 'reservation');
// CRUD table
$this->load->helper('crud');
$crud = generate_crud('tbl_reservasi');
$crud->set_subject('Reservasi');
//Label Fields
$crud->display_as('kdReservasi','Kode Reservasi');
$crud->display_as('kd','Ruangan');
$crud->display_as('id','User');
$crud->display_as('tanggalMasuk','Tanggal Masuk');
$crud->fields('kd','id','tanggalMasuk');
$crud->required_fields('kd','id','tanggalMasuk');
//Kolom Input dan Callbacks
$crud->set_relation('kd','tbl_ruangan','{kd} - {kdRuangan} - {jenis} - {namaRuangan}', array('status' => 'Tersedia'));
$crud->set_relation('id','users','{id} - {email} - {first_name} {last_name}', array('active' => '1'));
$crud->callback_after_insert(array($this, 'status_update'));
//Cetak Halaman
$this->mTitle = "Reservation";
$this->mViewFile = '_partial/crud';
$this->mViewData['crud_data'] = $crud->render();
}
function status_update($post_array,$primary_key)
{
$_update = array(
"kd" => $primary_key,
"status" => 'Tidak Tersedia'
);
$this->db->update('tbl_ruangan',$_update, array('kd' => $primary_key));
return true;
}
Everytime i insert data, inserting ruangan
, user
, and tanggalMasuk
it doesn't directly change status
to Tidak Tersedia
. It changes after i insert 2 records with the same values.
All i want only if i insert record from tbl_reservasi
, then status
from tbl_ruangan
change to Tidak Tersedia
.