View Full Version : While loop, works for 1, not for AND

08-01-2008, 04:35 AM
So I am trying to get a while loop to display all staff members on a script. Administrators are level 1, and Secondary staff is level 3. That's the only two I want to include. Now if I set it for level 1 staff, it works. Or if I set it for level 3 staff, it works. but the AND will not work, nothing will be displayed that way. I don't understand...

$staffquery = doquery("SELECT user,stafflevel FROM {{table}} WHERE stafflevel='1' AND stafflevel='3' ORDER BY stafflevel", "users");

while ($staffrow = mysql_fetch_array($staffquery)) {

if ($staffrow["stafflevel"] == 1) { $person = "<font color=red><b>Administrator</b></font>"; }

elseif ($staffrow["stafflevel"] == 3) { $person = "<font color=green><b>Help Aid</b></font>"; }

$page .= "<tr><td>".$staffrow["user"]."</td><td>$person</td></tr>";


08-01-2008, 04:38 AM
There are no rows where stafflevel='1' AND stafflevel='3' at the same time. To get all the rows where stafflevel='1' OR stafflevel='3', you need to use OR.

08-01-2008, 04:58 AM
Ah, so AND would be picking them together for 1 output, or OR is for multiple outputs.....correct?

08-01-2008, 05:59 PM
AND is the same as &&
OR is the same as ||

AND means both statements must be true.
OR means either statements can be true.

08-01-2008, 06:16 PM
You could also use IN, which is similar to PHP's in_array() function:

SELECT user,stafflevel FROM {{table}} WHERE stafflevel IN ( 1, 3 ) ORDER BY stafflevel