php下拉打印所选项目

I am trying to print the selected dropdwon item. I have already written the code for dropdown to fetch a column from database.

Now i should print the only the id of selcted dropdown item. i don't know how to make it. please help me, this is my code

<? 
$query_name="SELECT id_cat,name FROM `fs01_metier_cat` ORDER BY `fs01_metier_cat`.`name` ASC";
$result = mysql_query ($query_name);

echo "<select name=category value=''></option>";
while($nt=mysql_fetch_array($result))
{
    echo "<option value=$nt[name]>$nt[name]</option>";
}
echo "</select>";



$query_id="SELECT id_cat FROM `fs01_metier_cat`";
$result1 = mysql_query ($query_id);
while($row = mysql_fetch_assoc($result1))
{
   echo $row['id_cat'];
}

?>

try this:

while($nt=mysql_fetch_array($result)){
    echo "<option value='{$nt['id_cat']}'>{$nt['name']}</option>";
}

with {} php can insert also array values into a string and you should set ' ' around the attribute "value"'s value (alot of values here.. ^^), that the html is w3c conform (i dont know if a browser would take it as correct without them..)

without the { } it would look like that:

while($nt=mysql_fetch_array($result)) {
    echo "<option value='".$nt['id_cat']."'>".$nt['name']."</option>";
}

depending on your editor code highlighting might work better in the second case ;)

and about the selected item:

i would suggest you to use jQuery to get the content of the selected item

var selectedId = $('#yourselectid option:selected').attr('value');

and then you can e.g. write it to the document or to a div:

document.write(selectedId);

or

$('#yourDivIdWhereYouWantToPutTheSelectedId').html(selectedId);

important: please note that i changed the value's index to id_cat because then you can handle the options with their id

Since the selected option changes everytime you change the dropdown selection, you can not handle this via php. There are ways to do that without a huge library like jQuery (since they are also just simple Javascript) but they simplify such things alot ;)