我有两张桌子,预订,客户
table #1 : reservation
------------------------
- reservation_id
- reservation_status
- customer_id
table #2 : customer
------------------------
- customer_id
- customer_name
- customer_status
我是codeigniter的新手,但我如何根据customer status
reservation id
(从0到1或1到某个值)
是否使用加入和更新或某种程度。 感谢
答案 0 :(得分:0)
尝试此查询:
$sql = 'UPDATE customer AS C JOIN reservation AS R ON R.customer_id=C.customer_id
SET C.customer_status = (CASE C.customer_status WHEN 1 THEN 0 ELSE 1 END)
WHERE R.reservation_id="2"';
$result = $this->db->query($sql);
if($result) {
echo "Success";
} else {
echo "fail";
}
通过以下方式检查您的查询:
echo $this->db->last_query();
答案 1 :(得分:0)
试试这段代码
UPDATE customer
JOIN reservation
ON customer.customer_id = reservation.customer_id
SET customer.customer_status = your_value;
WHERE reservation.reservation_id="your_id"';