Re: Querying MySQL using 'AND' / 'OR'
| From: | Christian Reiniger | Date: | Sat, 03 Feb 2001 18:32:13 +0000 |
| Subject: | Re: Querying MySQL using 'AND' / 'OR' | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-37972@lists.php.net to get a copy of this message | ||
On Saturday 03 February 2001 15:02, James, Yz wrote:
> $sql = "SELECT * FROM table
> WHERE username = '$username' AND password = '$password' AND
> site = 'theirsite' OR site = 'all'";
> So, without writing some if statements, is there any way of rewriting
> that $sql check so that it checks whether the user is an admin of
> either the individual subdirectory, or all of the sites? Like
>
> username: foo password: bar site: all
>
> or
>
> username: foo password: bar site: subdirectory
Simply use brackets to specify the evaluation order:
SELECT * FROM table
WHERE (username = '$username' AND password = '$password') AND
(site = 'theirsite' OR site = 'all')
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
"Never doubt that a small group of thoughtful, committed people can
change the world...
Indeed, it's the only thing that ever has."
- Margaret Mead