selection from a list box.

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

    #1

    selection from a list box.

    Hi, I am pretty new to php and have to implement this functionality to
    select a user from a list box. I have written the code for this, but
    the problem is after selecting a name and doing the required task, it
    again selects the first entry in the list box. So if there are 100
    users, the 100th one has to scroll down again and again.

    I need to modify this code so that until the session expires, if a
    person has selected his name once, that name will be selected in the
    listbox until he changes it.


    <select name="name" style="width: 120px;">
    <?php
    $query = sprintf("select * from person order by person_name");
    $result = mysql_query($qu ery);
    $i = 0;
    while($row = mysql_fetch_arr ay($result))
    {
    $i++;
    printf("<option
    value=\"$row[person_num]\">$row[person_name]</option>");
    }
    ?>
    </select>



    Regards,
    Piyush

  • jacob.ohara@googlemail.com

    #2
    Re: selection from a list box.

    i would probably save it to a session var but im also pretty new to php

    Comment

    • fiziwig

      #3
      Re: selection from a list box.


      When the selected name is being processed:

      session_start() ; // send session_id cookie to user
      $_SESSION['username'] = $uname;

      At the top of any file that needs to know:

      if(isset($_SESS ION['username'])) {
      $uname=$_SESSIO N['username'];
      }

      In the selection box:

      echo '<SELECT NAME="....>';
      echo '<OPTION..blahb lah..';
      if ($thisname==$un ame) echo 'SELECTED';
      echo '>'.$blahblah.$ '</OPTION>';

      --gary

      Comment

      Working...