我有一个表格字段' new_options'可以包含后续类型的数据:
我想设置$ options_exist =' no'如果满足条件1,2或3。 或$ options_exist ='是'如果满足条件4。
到目前为止,我有这个适用于1,3和4:
$str='string-a';
$opts_exist = strpos($product[new_options], $str);
if ($opts_exist == true) {
$options_exist='no';
}
elseif ($product[new_options]==''){
$options_exist='no';
} else {
$options_exist='yes';
}
我如何为string-b添加条件?
答案 0 :(得分:0)
在SQL中执行:
SELECT CASE WHEN new_options LIKE '%string-a%' THEN 'no'
WHEN new_options LIKE '%string-b%' THEN 'no'
WHEN new_options = '' THEN 'no'
ELSE 'yes'
END AS options_exist
FROM yourTable