Querying MySQL using 'AND' / 'OR'

From: Date: Sat, 03 Feb 2001 14:02:18 +0000
Subject: Querying MySQL using 'AND' / 'OR'
Groups: php.general 
Request: Send a blank email to php-general+get-37953@lists.php.net to get a copy of this message
Hi Guys, Quick question...... I've managed to write a function (thanks to help from people earlier in the week) which queries an admin table. There are currently four fields in the table; id, username, password, and 'site', where the 'site' means a subdirectory of my site that the particular admin user is allowed acces to change things in.... Now, each 'site' user is allowed access to only their site, but, being the owner of all the 'sites', my field contains the word "all." So, I used this to determine whether the user (when logged in) is firstly an administrator, and secondly what area of the site they're responsible for: $sql = "SELECT * FROM table WHERE username = '$username' AND password = '$password' AND site = 'theirsite' OR site = 'all'"; Now, as you can probably see, the table is querying whether the table has a row with fields: username, password, site OR Just a row with the field containing "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 ......... Hope that makes sense, and thanks in advance for any help :) James.

« previous php.general (#37953) next »