Jump to content

Recommended Posts

Posted

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!

Posted

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"; 
}  

Posted

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!

Posted

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'])

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

Posted
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)  

Posted

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

Posted
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

:getmecoat:

 

Toby

Posted
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 :D

Posted
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 :D

 

i'm already halfway down the corridor with my coat!!!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...