Log in

View Full Version : php string giving errors, please help me understand it?



BLiZZaRD
07-07-2006, 09:40 AM
Hello, I have a string that looks like this:



'title' => $location == 'postform' ? $txt['table_shown'] : $txt['table_hidden'],


What it does is tells each table what it's title is. Obviously the $txt['table_shown'] is defined as something like "Shown to all"

Like wise the $txt['table_hidden'] is defined as something like "Click for more options"

What I have done though is made 7 more Hidden ones for a total of 8. each is defined as $txt['table_hidden_a'] $txt['table_hidden_b'] etc... through _g

What I need to do now is add the _a through _g texts to the 'title'= string, but I don't know how...

I tried this:



'title' => $location == 'postform' ? $txt['table_shown'] : $txt['table_hidden'] : $txt['table_hidden_a'] : $txt['table_hidden_b'] : $txt['table_hidden_c'] : $txt['table_hidden_d'] : $txt['table_hidden_e'] : $txt['table_hidden_f'] : $txt['table_hidden_g'],


but got the error "Unexpected ":" in line 854.. blah blah

So how can I add those other strings there?

djr33
07-07-2006, 11:14 AM
Parenthises are your friend here.
You can't repeat the : operator... it's a very specific thing here.

IF THIS ? THEN THIS : ELSE THIS

So... what you have is:
IF, THEN, ELSE, ELSE, ELSE, ELSE.... which is weird.


Honestly, you may be able to use it like that and I could be wrong, but I think I'm on the right track.

If you're using standard "if" and "else" statements, you would use the elseif to continute, like:
if () {}
elseif () {}
elseif () {}
else {}

But the : is just else, so that doesn't really work.

You could always try layering, but that would get ugly... that syntax is only used for simple stuff... not for complex.

See if this helps.

I'd say just keep it simple, and use words, not weird symbols. But that's just me.

BLiZZaRD
07-07-2006, 12:45 PM
Sorry djr... that made no sense to me, LOL

the : works because originally there were only 2 options, now there are 9, well there WILL be if I can figure this out...

So basically I need to rewrite that string to show the 9 options instead of just the 2... somehow...



<edit> That came out wrong... I understood what you meant, the explination was very good, so thank you, however when yo usaid "parenthesis are my friend" How can I use the parens to show the 9 options? I tried and got "unexpected , " erro, so I put each option inside [] and got "unexpected [ " error...

headache I tell ya!

</edit>

Twey
07-07-2006, 01:44 PM
I don't understand what you're trying to accomplish. ($location == 'postform') can have two possible outcomes: true, or false. Therefore, you can only specify two options to the ternary operator. If you had some more conditions, you could do:

condition1 ? true1 : condition2 ? true2 : condition3 ? true3 : allfalse... and so on. But one condition can yield only two values.

BLiZZaRD
07-07-2006, 01:48 PM
It's for the Mod... I just can't find anywhere else to add the text for the title and descriptions for the boxes... there are only so many files that control them...