I have this table called ost_investigadores with the next fields:
nombre, topic_id, isactive, email
I have a form with these textbox:
Nombre:
Email:
I have about 400 records and I used the following code to create a combobox displaying the names so I can select one of them instead of writing their names by hand in a text box.
<td>
<select name="name">
<option value="" selected ></option>
<?
$services= db_query('SELECT topic_id, nombre, email FROM ost_investigadores
WHERE isactive=1 ORDER BY nombre');
if($services && db_num_rows($services)) {
while (list($name,$nombre) = db_fetch_row($services)){
$selected = ($info['name']==$name) ?'selected':''; ?>
<option value="<?=$nombre ?>"<?=$selected?>><?=$nombre?></option>
With the above code I get a combobox or select list with a list of my users´ name and I only have to select one, now THE PROBLEM that I have is that I would like to print out or get their email value with an echo, when I choose a name from the combobox I would like to get their corresponding email.
I have tried with this code:
$services= db_query(" SELECT email FROM ost_investigadores WHERE nombre='$nombre'");
list($email) = db_fetch_row($services);
echo "$email";
but nothing happens, instead using the variable $name If I wrote the name like nombre='Jonh Smith' I get his email.
Or I would like to do something like:
$services= db_query(" SELECT email FROM ost_investigadores WHERE nombre=<option value=" <?=$nombre ?>"<?=$selected?>><?=$nombre?></option>");
list($email) = db_fetch_row($services);
echo "$email";
So , What can I do to get their email once I select a name from the list?