0

我正在尝试将我的 SQL 查询更改为使用 BETWEEN 搜索/比较 LIKE 以从特定字段中获取 >= 搜索值的所有值......到目前为止无法使其工作。

  $searchcat = "brand";
  if (isset($_POST['searchcat'])) {
  $searchcat = $_POST['searchcat']; 
}
$selectVal = "LIKE %s";
if ($searchcat == 'quantity') {
$selectVal = "BETWEEN %s";
}else{
$selectVal == "LIKE %s";
}
mysql_select_db($database_prp, $prp);
$query_paperlist = sprintf("SELECT * FROM paperlist WHERE $searchcat $selectVal ORDER BY paperid ASC", GetSQLValueString("%" . $colname_paperlist . "%", "text"));
$query_limit_paperlist = sprintf("%s LIMIT %d, %d", $query_paperlist, $startRow_paperlist, $maxRows_paperlist);
$paperlist = mysql_query($query_limit_paperlist, $prp) or die(mysql_error());
$row_paperlist = mysql_fetch_assoc($paperlist);
4

1 回答 1

0

基于Mysql Docs,它是Between ... And。它更像是1<x<10。我认为在你的情况下Not (Between ... And ...)更合适的是not(1<x<10)=x<1 || x>10. Not (Between ... And ...)可用于大于运算符。你只需要确保你的小于永远不会是真的。

于 2012-04-20T16:16:41.087 回答