是否可以在多个LIKE查询中找出匹配的列?
e.g:
SELECT * FROM table WHERE col_a LIKE = '%B' OR col_b LIKE = '%A'
if(MATCHED COL_A){
do this;
}else{
do that;
}
答案 0 :(得分:2)
SELECT col_a, col_b FROM table WHERE col_a LIKE "%B" OR col_b LIKE "%A"
if (strpos($colA, $needle) !== false) {
// do this
} elseif (strpos($colB, $needle) !== false) {
// do that
}
答案 1 :(得分:2)
你可以简单地把你的条件放在select语句中,并用新的别名命名,对于匹配的列,它的布尔值为0/1,而=
之后也没有任何意义
SELECT *,
col_a LIKE '%B' AS match_cola,
col_b LIKE '%A' AS match_colb
FROM table WHERE col_a LIKE '%B' OR col_b LIKE '%A'
从查询中获取结果,您可以将其检查为
$result = fetch result from query;
//loop
if($result['match_cola'] == 1){
echo 'col_a matched';
}
//end loop