2017-06-06 54 views
0

我有2个表,预订客户更新笨的表#2基于表#1的ID数据

table #1 : reservation 
------------------------ 
- reservation_id 
- reservation_status 
- customer_id 

table #2 : customer 
------------------------ 
- customer_id 
- customer_name 
- customer_status 

我在笨新的,但我怎么可以更新/更改customer status(从0到1或1到某个值)基于reservation id

是否存在使用连接和更新或有些情况。 感谢

回答

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(); 
0

试试这个代码

UPDATE customer 
     JOIN reservation 
     ON customer.customer_id = reservation.customer_id 
SET  customer.customer_status = your_value; 
WHERE reservation.reservation_id="your_id"';