0

Hi

I am retrieving values from database for edit profile...

I have one query ..... i.e.

Based on department Id in database i am showing selected value in drop down box.... but while inserting how to insert department id.

$data = @mysql_query("select * from Department");
$array = array();
while ($row = mysql_fetch_assoc($data))
{
$id = $row['dept_id'];
$dname = $row['department_name'];
   echo '<option value='.$did.'>'.$dname.'</option>'."\n";

}

In above code $did is selected value from database..... but while inserting how to get $id .......can we write to values in option field?

Thanks in advance

Edited by Dani: Formatting fixed

4
Contributors
4
Replies
8
Views
5 Years
Discussion Span
Last Post by vaultdweller123
0

Your code is almost OK. I only added <select> and </select> tags on the beginning and end of the while loop and double quotes around $id (and changed $did in your code to $id).

$data = @mysql_query("select * from Department");
$array = array();

echo '<select>';

while ($row = mysql_fetch_assoc($data))
{
    $id = $row['dept_id'];
    $dname = $row['department_name'];

    echo '<option value="'.$id.'">'.$dname.'</option>'."\n";
}

echo '</select>';
0

This not my problem ....I already keep select....I retrieve values in to drop down....I am doing edit profile.... suppose user selects a department electrical while registering to website and after login he want to edit department...at that time i want to show selected value as electrical in drop down box.

I can able do these....but there is a problem ....that is how can i use to option values in drop down box...like one value already selected .....and other value to insert in database?

0

if you're replacing department display the current(selected) value in a text box
and let users select a new department from the drop down

0

you got typo error, you type $did instead of $id
changed this code

echo '<option value='.$did.'>'.$dname.'</option>'."\n";

to

echo '<option value='.$id.'>'.$dname.'</option>'."\n";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.