glennda Posted March 7, 2011 Posted March 7, 2011 I have one of these that works ";} elseif ($lib_num<'22') {echo "web/img/tick.png"; } elseif ($lib_num=='28') { echo "web/img/full.png"; } else {echo "web/img/warning.png"; Tried changing it for another part of my page but can't see where i'm going wrong if ($lib_opened['active']=='1') { echo "web/img/full.png"} else { echo $lib_num ." of 28 PCs used" .; } I just get the error PHP Parse error: syntax error, unexpected '}', expecting ',' or ';' i've been coding all day and my eyes hurt now!
penfold_99 Posted March 7, 2011 Posted March 7, 2011 This should work. You had a missing ; on the first echo line and the second one you had an extra . if ($lib_opened['active']=='1') { echo "web/img/full.png"; } else { echo $lib_num ." of 28 PCs used"; }
glennda Posted March 7, 2011 Author Posted March 7, 2011 I did that the ; on the first line but in the wrong place and it kicked up a fuss the first time! Time for me to sleep and then look at it again tomorrow thanks its working now!
powdarrmonkey Posted March 8, 2011 Posted March 8, 2011 Why are you evaluating $lib_opened as a string?? Is it supposed to be a boolean value? Don't evaluate "if 1", evaluate "if true": if ($lib_opened['active'] == true) which protects you against rogue values. (For reference, 0 == false and !0 == true.) Then you can take a short cut, and use your variable's sensible name to make it easier to read: if ($lib_opened['active'])
glennda Posted March 8, 2011 Author Posted March 8, 2011 Why are you evaluating $lib_opened as a string?? Is it supposed to be a boolean value? Don't evaluate "if 1", evaluate "if true": because there are also values for 2 and 3 its not simply a value of 0 and 1 0 is open, 1, is closed, 2 is closed due to vandalism, 3 is closed for an event its simpler to have 0,1,2,3 then random words in the database. Its for the Display of computers not being used i have made to slot into Webmans Login Tracker. On another part it echo's text rather then an image, but i had that part working.
powdarrmonkey Posted March 8, 2011 Posted March 8, 2011 because there are also values for 2 and 3 its not simply a value of 0 and 1 That's fair enough, but you still shouldn't be evaluating it as a string: if ($lib_opened['active'] == 1)
powdarrmonkey Posted March 8, 2011 Posted March 8, 2011 How should i do it then? as above: if ($lib_opened['active'] == 1)
glennda Posted March 8, 2011 Author Posted March 8, 2011 Thats how I have it above if ($lib_opened['active']=='1') { echo "web/img/full.png"; } else { echo $lib_num ." of 28 PCs used"; } Apart from no spaces
powdarrmonkey Posted March 8, 2011 Posted March 8, 2011 No, you don't. You have wrapped the number in single quotes, so it is cast to a string before evaluation. This is a BAD thing and it can lead to hard-to-find bugs.
glennda Posted March 8, 2011 Author Posted March 8, 2011 No, you don't. You have wrapped the number in single quotes, so it is cast to a string before evaluation. This is a BAD thing and it can lead to hard-to-find bugs. Ahh yes i see now! both me and the other tech missed that! I will change it Toby
sparkeh Posted March 8, 2011 Posted March 8, 2011 Thats how I have it above No, you don't. You have single quotes around the one when evaluating the result meaning you are comparing a the result against a string, which you do not want to do. Powdarrmonkey's does not, meaning his compares the result to a value, which you do want to do. edit: Too late
glennda Posted March 8, 2011 Author Posted March 8, 2011 No, you don't. You have single quotes around the one when evaluating the result meaning you are comparing a the result against a string, which you do not want to do. Powdarrmonkey's does not, meaning his compares the result to a value, which you do want to do. edit: Too late i'm already halfway down the corridor with my coat!!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now