|
Posted by Captain Paralytic on 04/23/07 15:45
On 23 Apr, 15:24, Rob <nos...@plea.se> wrote:
> Hello,
>
> When i use the following query:
>
> $sql = "SELECT * FROM table WHERE 1 AND project like '%$zoek%' and publi
> NOT like 'no' order by jaar DESC LIMIT 0, 100";
>
> I get what i want: all projects named '%$zoek%' where publi is not like
> no.
>
> However, when i want that '%$zoek%' is not only to be searched for in
> project but also in locatie I use the next query:
>
> $sql = "SELECT * FROM table WHERE 1 AND project like '%$zoek%' OR
> locatie like '%$zoek%' and publi NOT like 'no' order by jaar DESC LIMIT
> 0, 100";
>
> This does not do the thing I want:
> records where publi is no are shown where I want them to be hidden.
>
> Where do things go wrong?
>
> Rob
Your problem is operator precedence.
See: http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
What you need to do is:
$sql = "SELECT * FROM table WHERE 1 AND (project like '%$zoek%' OR
locatie like '%$zoek%') and publi NOT like 'no' order by jaar DESC
LIMIT
0, 100";
Note the brackets.
[Back to original message]
|