假设您正在运行一个查询,并且您有很多不同的用户输入可能找不到完全匹配的内容。现在是否可以执行以下操作?
$query = "SELECT *,
CASE matchingValues
WHEN $field1 LIKE '$a' THEN value = '1' ELSE value = '0'
WHEN $field2 LIKE '$b' THEN value = '1' ELSE value = '0'
WHEN $field3 LIKE '$c' THEN value = '1' ELSE value = '0'
WHEN $field4 LIKE '$d' THEN value = '1' ELSE value = '0'
WHEN $field5 LIKE '$e' THEN value = '1' ELSE value = '0'
END AS score
FROM . $usertable
WHERE
$field1 LIKE '$a' AND
$field2 LIKE '$b' AND
$field3 LIKE '$c' AND
$field4 LIKE '$d' AND
$field5 LIKE '$d'
ORDER BY score DESC";
if($result = mysql_query($query)) {
if(mysql_num-rows($result)==NULL) {
echo 'No Results Found';
}else{
....