-1

我想根据以下表格过滤mysql结果

www.dabndash.com/filter.php

我一直在尝试的过滤器的mysql代码是:

SELECT DISTINCT * FROM paintings 
  WHERE (price BETWEEN '$min_price' AND '$max_price') 
  AND (orientation = '$orientation1' OR orientation = '$orientation2' OR orientation = '$orientation3')
  AND (size_diagonal BETWEEN '$size_min' AND '$size_max')
  AND (primary_color = '$primary_color' AND secondary_color = '$secondary_color')

我不确定为什么查询没有过滤结果。即使用户输入了任何一个字段,它也应该过滤结果。

4

2 回答 2

0

您应该只使用用户选择的参数并从中构建查询。用户似乎可以将方向、大小和原色过滤器留空。

例如,如果$orientation1为空,则查询将返回零个结果(假设所有画作的方向均非空。

尝试使用较少的 where 子句运行查询,并验证您是否获得了预期的结果。

于 2012-05-03T09:41:58.073 回答
-1
SELECT DISTINCT * FROM paintings   WHERE (price BETWEEN '$min_price' AND '$max_price') 
                          AND (orientation = '$orientation1' OR orientation = '$orientation2' OR orientation = '$orientation3')
                          AND (size_diagonal BETWEEN '$size_min' AND '$size_max')
                          AND (primary_color = '$primary_color' AND secondary);
于 2012-05-03T09:31:21.803 回答