Problem getting value from query
Posted: Sat Nov 20, 2010 3:18 pm
I couldnt exactly search for this problem because it's a little hard to describe.
Im trying to get a dynamic list in a form. I do this by doing a query to the database and i get the name and the ID. This is what i get displayed:

Now, when i send the form, im recieving the NAME of the department. However i want to get the id only. This is my code:
so the problem here arises here:
because it seems that im sending "nombre" when i want to send "id_dept". However, if i put instead
my drop down list displays the ID or the departments, which is not the desired outcome.
I've thought of sending both the ID and the department name, but im not sure how to "cut" the department name afterwards so i get only the id.
any suggestions are very welcome, thanks!
also, im not quite sure what im acomplishing with echo "<select name = id_dept>"; but if i remove it my drop down list is blank.
Im trying to get a dynamic list in a form. I do this by doing a query to the database and i get the name and the ID. This is what i get displayed:

Now, when i send the form, im recieving the NAME of the department. However i want to get the id only. This is my code:
Code: Select all
<?
//DB conection
mysql_connect("localhost","adjusted_reloj","xxxxx");
//SQL command
$sSQL="Select id_dept, nombre From department Order By nombre";
$result=mysql_db_query("adjusted_reloj",$sSQL);
echo "<select name = id_dept>";
//Show the drop down list
while ($row=mysql_fetch_array($result))
{echo '<option>'.$row["nombre"];}
mysql_free_result($result)
?>
Code: Select all
echo '<option>'.$row["nombre"];Code: Select all
echo '<option>'.$row["id_dept"];I've thought of sending both the ID and the department name, but im not sure how to "cut" the department name afterwards so i get only the id.
any suggestions are very welcome, thanks!
also, im not quite sure what im acomplishing with echo "<select name = id_dept>"; but if i remove it my drop down list is blank.