【问题标题】:UPDATE table and SET column based on condition根据条件更新表和 SET 列
【发布时间】:2017-11-23 14:31:43
【问题描述】:

这就是我的代码现在的样子:

$stmt = $link->prepare("UPDATE product SET product_price_lowest = $adPrice WHERE product_id = $prodId");
$stmt->execute();


我只想SET product_price_lowest TO $adPrice:
IF $adPrice product_price_lowest


我该怎么做?

【问题讨论】:

    标签: mysql if-statement pdo conditional


    【解决方案1】:

    然后将其添加到WHERE 子句中

    WHERE product_id = $prodId
    AND $adPrice < product_price_lowest
    

    【讨论】:

    • 哇,它成功了,非常感谢!我从来没有想过使用“AND”作为 IF 语句。
    猜你喜欢
    • 2011-07-01
    • 2019-07-24
    • 1970-01-01
    • 2021-12-10
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2022-01-23
    相关资源
    最近更新 更多