Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-01-2008, 03:35 AM   PM User | #1
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
While loop, works for 1, not for AND

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...

Code:
$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>";

}
masterofollies is offline   Reply With Quote
Old 08-01-2008, 03:38 AM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,712
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is online now   Reply With Quote
Old 08-01-2008, 03:58 AM   PM User | #3
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Ah, so AND would be picking them together for 1 output, or OR is for multiple outputs.....correct?
masterofollies is offline   Reply With Quote
Old 08-01-2008, 04:59 PM   PM User | #4
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
AND is the same as &&
OR is the same as ||

AND means both statements must be true.
OR means either statements can be true.
Apothem is offline   Reply With Quote
Old 08-01-2008, 05:16 PM   PM User | #5
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
You could also use IN, which is similar to PHP's in_array() function:
Code:
SELECT user,stafflevel FROM {{table}} WHERE stafflevel IN ( 1, 3 ) ORDER BY stafflevel
__________________
ZCE
kbluhm is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:42 PM.


Advertisement
Log in to turn off these ads.