|
-
Dec 27th, 2005, 04:40 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Multiple IF's
hi, how can i have several IF statements in a statement. if you know vb then it may make more sence as:
VB Code:
If var1 = "something" then
If var2 = "somethingelse" then
Do_Something
End If
End If
does that help? this is like the best i can explain which either makes me stupid or not that good at thinking.
thanks, dandono
Last edited by dandono; Dec 28th, 2005 at 05:26 PM.
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 27th, 2005, 08:16 PM
#2
PowerPoster
Re: Multiple IF's
if ($var1 == $var2 && $var2 == $var3) {
}
&& = And
|| = Or
That what your after?
-
Dec 28th, 2005, 02:26 AM
#3
Fanatic Member
Re: Multiple IF's
If you want it similar to the code you have, i think you can just do:
Code:
if($var1 == "hi"){
if($var2 == "all"){
// stuff
}
// other stuff if you want
}
sql_lall 
-
Dec 28th, 2005, 04:56 AM
#4
Thread Starter
Hyperactive Member
Re: Multiple IF's
thanks. i have not been able to figure that one out for the time i have "known" php.
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 28th, 2005, 08:22 AM
#5
Fanatic Member
Re: Multiple IF's
you could also use if/elseif/else statements.
-
Dec 28th, 2005, 09:43 AM
#6
Thread Starter
Hyperactive Member
Re: Multiple IF's
so i could do
PHP Code:
If (var1 == "blah")
{
echo "blah";
}elseif(var2 == "blah2")
{
echo "blah2";
}
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 28th, 2005, 04:05 PM
#7
Fanatic Member
Re: Multiple IF's
Yes, the best format is as follows.
PHP Code:
If (var1 == "blah") {
echo "blah";
} elseif (var2 == "blah2") {
echo "blah2";
} else {
echo "blah3";
}
You can put as many elseif's as you want, I would suggest you also use the "else" at the end as a "catch all" incase the if statements dont catch whats being passed, kind of like error checking.
I use it and have it post the info its looking at so if I ever see it, I know whats going on.
-
Dec 28th, 2005, 05:24 PM
#8
Thread Starter
Hyperactive Member
Re: Multiple IF's
ok thanks. this will help in a new login script for my website.
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 29th, 2005, 10:26 AM
#9
Thread Starter
Hyperactive Member
Re: [RESOLVED]Multiple IF's
i got an error on this line of code:
PHP Code:
}
elseif($admin == "daniel")
{
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\main\index.php on line 22
i dont know what is wrong. if it helps i can post the whole code but it is 99 lines of code but most of it is html
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 29th, 2005, 10:28 AM
#10
Thread Starter
Hyperactive Member
Re: [RESOLVED]Multiple IF's
sorry i fixed it. the problem was that i was echoing a string and it was started with the " type thing and closed with the ' type thing. my brain is a bit slow today and i cant remember what they are called
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 29th, 2005, 02:41 PM
#11
Hyperactive Member
Re: [RESOLVED]Multiple IF's
double "quotes" single 'quotes'
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Dec 30th, 2005, 06:47 AM
#12
Thread Starter
Hyperactive Member
Re: [RESOLVED]Multiple IF's
oh yeah
If there is only one perfect person in the universe, does that make them imperfect?
-
Dec 30th, 2005, 07:41 AM
#13
Re: [RESOLVED]Multiple IF's
Try to use single quotes rather than double quotes, unless you want embedded variables and/or escape sequences such as \n in the string.
-
Dec 30th, 2005, 09:57 AM
#14
Thread Starter
Hyperactive Member
Re: [RESOLVED]Multiple IF's
i normaly use single quotes because if you do something like
PHP Code:
echo "<img src="someimg.jpg">";
then it thinks the string ends at "src=" and then makes an error but if you did
PHP Code:
echo '<img src="someimg.jpg">';
then it would work fine.
If there is only one perfect person in the universe, does that make them imperfect?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|