开发者

PHP MYSQL search for specific lines

I want to make a query only开发者_JAVA百科 between some specific lines. (make a query where word = title, but the data only between line 8, line 9, line 10). But my code still turn back all the result.(it will print line 33, line 36 ...) How to make a right query? Thanks.

$where = " field_1 = '$word' OR field_2 = '$word' OR field_3 = '$word' ";
SELECT * FROM table WHERE $where AND (id='8' OR id='9' OR id='10');


AND has higher precedence than OR so you need parentheses around $where:

SELECT * FROM table WHERE ($where) AND (id='8' OR id='9' OR id='10');

Without the parentheses it evaluates as:

SELECT *
FROM table
WHERE field_1 = '$word' OR
      field_2 = '$word' OR
      (field_3 = '$word' AND (id='8' OR id='9' OR id='10'))


$where = " field_1 = '$word' OR field_2 = '$word' OR field_3 = '$word' ";
SELECT * FROM table WHERE $where AND (id='8' OR id='9' OR id='10') LIMIT 8,3;

That should grab 3 records starting with line 8. Does that work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜