selection from a list box.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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;">
$query = sprintf("select * from person order by person_name");
$result = mysql_query($query);
$i = 0;
while($row = mysql_fetch_array($result))


Re: selection from a list box.

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

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($_SESSION['username'])) {

In the selection box:

echo '<SELECT NAME="....>';
  echo '<OPTION..blahblah..';
  if ($thisname==$uname) echo 'SELECTED';
  echo '>'.$blahblah.$'</OPTION>';


Site Timeline