将给定 ID 的数据更新到具有相同 ID CodeIgniter 3 的另一个表
Update data from given ID to another tables with same ID CodeIgniter 3
我想创建一个函数,从 booking.booking_id
获取的控制器端函数的给定 $id 参数更新 client.client_status 数据
这是我的控制器
function end($book_id = null) {
if (!empty($book_id)) {
// Booking Table
$table = 'booking';
$where = [
'book_id' => $book_id,
];
$data = [
'room_status' => 1,
];
$this->Model_Data->booking_update($table, $where, $data);
// Client Table
$table = 'client';
$client_id = $???????; // How to get booking.client_id from given id parameters
$where = [
'client_id' => $client_id,
];
$data = [
'room_status' => 1,
];
$this->Model_Data->booking_update($table, $where, $data);
$this->session->set_flashdata('book_ended', 'Book Ended');
redirect('book');
}
else {
$this->session->set_flashdata('book_end_error', 'Book End Error');
redirect('book');
}
}
这是我的 SQL 表
根据您在问题中的评论,book_by_client_id
等于 client_id
那么 :
访问单行:
(1) 作为对象的结果
$data_result = $this->db->get_where('booking',array('book_id'=>$book_id ))->row();
$book_by_client_id =$data_result->book_by_client_id;
$client_id = $book_by_client_id; // client_id
(2) 结果为数组
$data_result = $this->db->get_where('booking',array('book_id'=>$book_id ))->row_array();
$book_by_client_id =$data_result['book_by_client_id'];
$client_id = $book_by_client_id; // client_id
注意: 了解有关 row() 的更多信息; && row_array();
https://codeigniter.com/userguide3/database/results.html#result-rows
我想创建一个函数,从 booking.booking_id
获取的控制器端函数的给定 $id 参数更新 client.client_status 数据这是我的控制器
function end($book_id = null) {
if (!empty($book_id)) {
// Booking Table
$table = 'booking';
$where = [
'book_id' => $book_id,
];
$data = [
'room_status' => 1,
];
$this->Model_Data->booking_update($table, $where, $data);
// Client Table
$table = 'client';
$client_id = $???????; // How to get booking.client_id from given id parameters
$where = [
'client_id' => $client_id,
];
$data = [
'room_status' => 1,
];
$this->Model_Data->booking_update($table, $where, $data);
$this->session->set_flashdata('book_ended', 'Book Ended');
redirect('book');
}
else {
$this->session->set_flashdata('book_end_error', 'Book End Error');
redirect('book');
}
}
这是我的 SQL 表
根据您在问题中的评论,book_by_client_id
等于 client_id
那么 :
访问单行:
(1) 作为对象的结果
$data_result = $this->db->get_where('booking',array('book_id'=>$book_id ))->row();
$book_by_client_id =$data_result->book_by_client_id;
$client_id = $book_by_client_id; // client_id
(2) 结果为数组
$data_result = $this->db->get_where('booking',array('book_id'=>$book_id ))->row_array();
$book_by_client_id =$data_result['book_by_client_id'];
$client_id = $book_by_client_id; // client_id
注意: 了解有关 row() 的更多信息; && row_array();
https://codeigniter.com/userguide3/database/results.html#result-rows