Results 1 to 5 of 5

Thread: php string giving errors, please help me understand it?

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default php string giving errors, please help me understand it?

    Hello, I have a string that looks like this:

    PHP Code:
    '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:

    PHP Code:
    '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?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    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>
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:
    Code:
    condition1 ? true1 : condition2 ? true2 : condition3 ? true3 : allfalse
    ... and so on. But one condition can yield only two values.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    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...
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •