View Full Version : either : or command to an if/else?

12-15-2006, 12:46 PM
I have some lines in a php script that controls the location of images (in this case smileys). Right now there are 2 options the post form and the pop up window.

Okay, so what I want to do is add more pop up windows to store more and different smileys in them.

Currently, one such line looks like this:

$location = empty($row['hidden']) ? 'postform' : 'popup';

Obviously this defines the location var. and as you can see there are only 2 options 'postform' and 'popup' this is evident by the *:* yes?

So I need a way to rewrite this (and the other lines) so I can include 'popup_a', 'popup_b' etc. I have a total of 8 pop ups, (including the original) that need to be included.

Perhaps a nested if/else statement? I am just not sure how to write this out.

I then will need to add something to the MySQL database to accept the different locations wont I? right now it has 3 options 0, 1 and 2 where 0 is the 'postform' and the 2 is the 'popup' and the 1 means hidden.

What would I need to edit there to include 3 - 9 where 3 = 'popup_a' and so on. to 9 = 'popup_g'

Advise? Thanks!

12-30-2006, 06:05 AM
Well, remember that parentheses are your friend in the case of trying to write something on one line.
You could write something like:

cond1 ? cond2 : (cond3 ? cond4 : (...));

...or something like that...

12-30-2006, 05:46 PM
I think I understand what you mean. I will give it a go in a couple days when I can find some time (just started a new job last week and am playing catch up :) )

Thanks for the idea, I will let you know what shakes.

12-30-2006, 06:06 PM
There are other options.... that was just a quick thought.
However, using words is helpful for reading it.
If makes more sense than ?... most of the time.