【发布时间】:2016-08-30 04:31:34
【问题描述】:
我有一个属性表,它定期从 XML 提要更新。如果属性不在它插入的数据库中;如果它在那里,它会更新它。但用户也可以通过网站后端的表单更新字段。如果用户更新了一个字段,它会标记它并将状态更改为 1。
我的桌子是这样的:
heading | nice house
up_heading | 1
price | 40000
up_price | 0
在这种情况下,每日cron作业运行更新时,它不会更新标题,因为up_heading的状态为1,但它会更新价格,因为up_price的状态为0。
所以我的问题是,我怎样才能编写一个高效的更新查询,例如:
update property
set heading = $heading
case up_heading = 0, set price = $price
case up_price = 0,
等等直到where p_id = %p_id?
【问题讨论】:
-
这就是你要找的东西:stackoverflow.com/questions/17265522/…
-
我要做的是在 cron 作业脚本中使用 PHP 来解析字段并设置必要的数据,然后运行带有 WHERE 子句的简单 UPDATE sql 语句并避免查询中的条件。
-
set heading = $heading -
这是我目前的代码 if($up_p_advert_heading == 0){$update_p_advert_heading = "p_advert_heading = '$p_advert_heading',";} else{ $update_p_advert_heading = "";} if($ up_p_postcode == 0){$update_p_postcode = "p_postcode = '$p_postcode', p_lon = '$p_lng', p_lat = '$p_lat', ";} else{$update_p_postcode = "";} if($up_p_price == 0 ){$update_p_price = "p_price = '$p_price', p_price_numeric = '$p_price_numeric',";} else{$update_p_price = "";}
-
请不要在 cmets 中转储代码,更新您的问题stackoverflow.com/posts/37032762/edit