Page 1 of 1
if and or
Posted: Mon Feb 16, 2004 5:24 pm
by Infinity
could anyone tell me the format for the php if and statement ie
if($userdata['user_rank']==1 and $userdata['user_rank']==2)
and the php if or statement ie
if($userdata['user_rank']==1 or $userdata['user_rank']==2)
thanx
Posted: Mon Feb 16, 2004 5:27 pm
by DuFF
You've already got it!

Those are correct, but are usually just used alternatively to:
Code: Select all
<?php
if($userdata['user_rank'] == 1 && $userdata['user_rank'] == 2)
{
//dostuff
}
if($userdata['user_rank'] == 1 || $userdata['user_rank'] == 2)
{
//dostuff
}
?>
Posted: Mon Feb 16, 2004 5:32 pm
by tim
i dont see anythign wrong with that cept that the "and" needs to be && and the "or" should be ||... just operators.
To keep the code clean, atleast its how I do it is i assign the row results as a var, IE:
Code: Select all
<?php
$sql = "SELECT * from whatever";
$quer = mysql_query($sql);
$row = mysql_fetch_array($quer);
$exam = $row["user"];
?>
Just now you can use $exam instead of typing out the row call.
:/edit - man duff thats twice you got me today, your fired. =]
Posted: Mon Feb 16, 2004 7:51 pm
by McGruff
tim wrote:i dont see anythign wrong with that cept that the "and" needs to be && and the "or" should be ||... just operators.
Using "and" and "or" is perfectly acceptable. Only difference is [php_man]
http://uk.php.net/manual/en/language.op ... precedence[/php_man]
Posted: Mon Feb 16, 2004 11:29 pm
by Infinity
thanx guys my site is coming together nicely due to peeps like you helping us noobs
