if($row['p1'] == 1 && $row['p2'] == "a" && $row['notes'] not like '%mouse%') {...}
这不是 MySQL 语法。它看起来像 PHP,在 PHP 中你不能使用LIKE
. 尝试使用字符串比较运算符,例如strstr
. http://php.net/manual/en/function.strstr.php
Mysql 风格
在没有鼠标的情况下获取所有行的查询可能是这样的:
SELECT * FROM `tablename`
WHERE `notes` NOT LIKE '%mouse%';
或者从 php 数组中获取排除项:
$condition = "WHERE ";
$first = true;
foreach($exclusions as $ex) {
if(!$first) $condition .= " AND "; // or use OR
$condition .= "`notes` NOT LIKE \"%$ex%\"";
$first = false;
}
$complete_query = "SELECT * FROM `tablename` $condition;";