php - 将数据从给定 ID 更新到具有相同 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 表
解决方案
根据您在 Question 中的评论,book_by_client_id
等于client_id
then for :
访问单行:
(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() 的更多信息;&& 行数组();
https://codeigniter.com/userguide3/database/results.html#result-rows
推荐阅读
- c# - 当不同的客户端(连接到同一个端口)发送数据时,服务器端 TcpClient 的 stream.read 没有数据
- reactjs - 运行 onKeyDown 函数时转到 NavLink
- android - 如何知道静音铃声的 URI?
- python - 比较 Python 中的两个表并返回已更改的行
- flow-project - 运行/example/rllib/green_wave.py时如何解决tensorflow版本问题
- docker - 如何修复简单 hdfs HA 集群中的“HA 未启用”错误
- excel-formula - 有没有办法在给定的 +/- 范围内使用 COUNTIF 进行部分数字匹配?
- angular - Angular 7.ngx-material-timepicker,切换按钮未正确对齐
- html - 如何在段落上方居中这个标题?
- asp.net-mvc - MVC 视图中的下拉列表