我有3个表,tbl_reservasi
,tbl_ruangan
和user
。
我想将tbl_ruangan.status
从Tersedia
更新为Tidak Tersedia
。
这是我的控制人员:
<?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;
}
每次我插入数据,插入ruangan
,user
和tanggalMasuk
时,它都不会直接将status
更改为Tidak Tersedia
。在插入具有相同值的2条记录后,它会发生变化。
我想要的只是当我从tbl_reservasi
插入记录,然后status
从tbl_ruangan
更改为Tidak Tersedia
。