session info and pull down lists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mammothman42@hotmail.com

    #1

    session info and pull down lists

    hi

    i have a html pull down list (<SELECT etc etc <OPTION VALUE .....) and
    i have the particular value the user last chose it to be in a
    $_SESSION['value']. How do i set the selected item of the list to this
    one? I can just add it in as the selected item of the list but then it
    appears twice. Get me? lol, hope so.

    cheers
    dave

  • Ian.H

    #2
    Re: session info and pull down lists

    On 15 Sep 2004 05:56:10 -0700, mammothman42@ho tmail.com wrote:
    [color=blue]
    >hi
    >
    >i have a html pull down list (<SELECT etc etc <OPTION VALUE .....) and
    >i have the particular value the user last chose it to be in a
    >$_SESSION['value']. How do i set the selected item of the list to this
    >one? I can just add it in as the selected item of the list but then it
    >appears twice. Get me? lol, hope so.
    >
    >cheers
    >dave[/color]


    Put it in a loop:

    <?php
    $foo = array(
    'stuff' => 'for',
    'select' => 'box'
    );
    ?>

    <select name="foo">
    <?php
    foreach ($foo as $key => $value) {
    ?>
    <option value="<?php echo $key;?>"
    <?php
    echo ($_SESSION['value'] == $value) ?
    'selected="sele cted"' :
    '';
    ?>
    />$value</option>
    <?php
    }
    ?>
    </select>


    Formatted above to fit within news client easier.

    You can change the line:


    echo ($_SESSION['value'] == $value) ?

    to

    echo ($_SESSION['value'] == $key) ?


    if looking for a key match rather than value.


    HTH =)



    Regards,

    Ian

    --
    Ian.H
    digiServ Network
    London, UK

    Comment

    Working...