#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2

    Select option from database


    Hi. I have a database which holds a 'Task status' this can be
    - klaar
    - bezig
    - hold


    Now when the users sets a status. I want the user to see what he has set, problem is with my method that it shows
    - hold ( currently set )
    - klaar
    - bezig
    - hold


    So it's showing the other value again cause it doesn't know that this is the selected one. How can i make sure the select doesn't repeat options.. this is my code

    PHP Code:
    <select name="status[]">
    <option selected="selected"><?= $project['taskstatus'?></option>
    <option value="klaar">Klaar</option>
    <option value="bezig">Bezig</option>
    <option value="hold">Hold</option>
    </select>
    Thanks.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    Set selected on the option that matches the taskstatus.
    PHP Code:
    ?><select name="status[]"> 
    <option value="klaar" <?= ($project['taskstatus'] == 'klaar' 'selected="selected"' ''?>>Klaar</option> 
    <option value="bezig"<?= ($project['taskstatus'] == 'bezig' 'selected="selected"' ''?>>Bezig</option> 
    <option value="hold"<?= ($project['taskstatus'] == 'hold' 'selected="selected"' ''?>>Hold</option> 
    </select>
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    PHP Code:
    $options = array('klaar''bezig''hold');

    foreach ( 
    $options as $option ) {
      echo 
    '<option' 
        
    . ($option == strtolower($project['taskstatus']) ? ' selected="selected"')
        . 
    ' value="' $option '">' ucfirst($option) . '</option>';

    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    @requinix : smart solution! why didn't i think of that! thanks!

    @ManiacDan : I was also thinking of array but didn't find a working solution. what's ucfirst ?
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    The PHP manual has all the information needed to answer "what is this function"
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by ManiacDan
    The PHP manual has all the information needed to answer "what is this function"
    I know that the manual holds that information. But since this was an open topic i thought i'd just ask it. My apoligies
  12. #7
  13. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    It is, and we're totally free to discuss stuff, but questions like "what does this function do?" really are best answered by a trip to the manual. There's much more information there than anyone here would be willing to type out.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    875
    Rep Power
    275
    is that "<?= " considered a legit longform php open tag example now?(I thought only <?php was accepted)
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by DonR
    is that "<?= " considered a legit longform php open tag example now?(I thought only <?php was accepted)
    PHP Code:
    <?= $var ?>
    echo's the var immediatly

    it's like

    PHP Code:
    <? echo $var ?>
  18. #10
  19. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    <?= is still technically a short tag but it's now guaranteed to be available (since 5.4 I think) regardless of the short tags setting.
  20. #11
  21. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    It was supposed to be removed from the language but people like Requinix are old dogs and can't be taught new tricks, and they complained loudly enough that it got put back into the language forever.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  22. #12
  23. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by ManiacDan
    It was supposed to be removed from the language but people like Requinix are old dogs and can't be taught new tricks, and they complained loudly enough that it got put back into the language forever.
    Are there other nice php shorttags that make typing easier? the <?= is really handy!

    Comments on this post

    • requinix agrees : it really is so don't pay attention to Dan. actually that's a good idea regardless

IMN logo majestic logo threadwatch logo seochat tools logo