linked combo box's from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<option value="<?php echo $e_dept; ?>" <? echo (isset($_POST['select_dept']) && $_POST['select_dept'] == $row['select_dept'] ? ' selected="selected' : '');?>> <?php echo $e_dept; ?> </option>
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

Hi Jcart

it is not working, but if i explain whats happening - you might be able to see whats wrong.

there is a combo box to select the dept (onchange)

this bring up a list of users in that dept - displayed in a list. click on a user and click add (then goes to user_add.php then back)

and when it comes back the users are no longer in the list, because the first option reset itself.

now is your code you gave me not working because i go from one page to another and back again?

and if you could, explain what the code does that is in the select box.

thank you!

my code for that select box looks like this now

Code: Select all

<form name="select_dept" action="/admin/users.php" method="post">
<select name="select_dept" onchange="this.form.submit();">
<option value="0" selected>Select Dept</option>
<option value="<?php echo $e_dept; ?>" <? echo (isset($_POST['select_dept']) && $_POST['select_dept'] == $row['select_dept'] ? ' selected="selected' : '');?>> <?php echo $e_dept; ?> </option>
  <?php
   include("conection.php");

     $query = "select DISTINCT(e_dept) from tbl_emp";
     $result = mysql_query($query);
     $num_results = mysql_num_rows($result);

     for ($i=0; $i <$num_results; $i++)
     {
     $row = mysql_fetch_array($result);
     $e_dept = $row['e_dept'];
?>
<option value="<?php echo $e_dept; ?>"> <?php echo $e_dept; ?> </option>
<?php
}
?>
</select>

<input type="hidden" name="s_id" value="<?php echo "$s_id"; ?>">
</form>
Post Reply