|
-
Nov 5th, 2008, 06:29 AM
#1
Thread Starter
Fanatic Member
syntax for if/else
Guys,
Not done much in php, could somebody help me with the syntax for this bit of code please?
Basically, if the current session alliance, alianta = "EximuS" then the filter should continue with the numele, else it should only show current alliance data.
tia
Bob
Code:
********* syntax wrong here ***
if ($_SESSION['alianta']=="EximuS") {
$aliantaSel = $_SESSION['numele'];
else
$aliantaSel = $_SESSION['alianta'];
****************************
if (isset($_GET['numele'])) {
$sql="SELECT
name,
sid,
volk,
rechte,
lastchange,
alianta
FROM
".PREFIX."spieler
WHERE
aktiv='1' AND
alianta='".$aliantaSel."'
ORDER BY
".$_SESSION['sort']."";
}
else {
$sql="SELECT
name,
sid,
volk,
rechte,
lastchange,
alianta
FROM
".PREFIX."spieler
WHERE
aktiv='1'
ORDER BY
".$_SESSION['sort']."";
}
// }
"I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings
-
Nov 5th, 2008, 07:02 AM
#2
Re: syntax for if/else
Hi staticbob,
The problem with the top code is you haven't closed and opened the braces, it should be
PHP Code:
if ($_SESSION['alianta']=="EximuS") { $aliantaSel = $_SESSION['numele']; } else { $aliantaSel = $_SESSION['alianta'];
And at the bottom, your final closing brace is commented out, that needs to be uncommented and back in your code because it is the closing brace with the parent if statement.
I would also suggest you keep your coding properly indented (I'm not sure if it looks the way it does because it's not in [ PHP][ /PHP] tags and I can see some if it is indented but some isn't), this will help you spot problems. For example I personally find it easy to read if statements in this format:
PHP Code:
if($condition) { if($condition2) { //code } else { //code } } else { //code }
Hope this helps
-
Nov 5th, 2008, 10:55 AM
#3
Re: syntax for if/else
I was slightly confused with this one, mainly because it looked as if you wanted to only execute one line of code after the first else...
... but, after scrolling down it would become apparent that the second condition statement is nested within the first...
My point, learn to indent code correctly, it makes it easier for yourself and us to read
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
|