更新mysql在php中同一列数据更新2在一个表中不同

时间:2017-11-18 08:31:38

标签: php mysql joomla3.0

我的列(jwqt5_rsform_submission_values)有2个值value1和value2 我希望changw value1为firstvalue,value2为secondvalue

我的PHP代码:

$user   = JFactory::getUser();
$db   = JFactory::getDbo();


      $db->setQuery("UPDATE `jwqt5_rsform_submission_values` SET `FieldValue` = 'firstvalue' WHERE `FieldValue` = 'value1'");
    return $db->loadResult();

$user   = JFactory::getUser();


$db1   = JFactory::getDbo();


      $db1->setQuery("UPDATE `jwqt5_rsform_submission_values` SET `FieldValue` = 'secondvalue' WHERE `FieldValue` = 'value2'");
    return $db1->loadResult();

1 个答案:

答案 0 :(得分:0)

您可以合并这样的查询:

UPDATE jwqt5_rsform_submission_values
SET FieldValue = CASE FieldValue
    WHEN 'value1' THEN 'firstvalue'
    WHEN 'value2' THEN 'secondvalue'
END
WHERE FieldValue IN ('value1', 'value2')