Jump to content

Help with select values


lingo5

Recommended Posts

Hi. I have cretaed this select that inserts the value "E_nombre" (company name).

 

<select name="E_nombre" id="E_nombre">
<option value="">Lugar del Evento</option>
<?php
do {  
?>
<option value="<?php echo $row_empresas_RS['E_nombre']?>"><?php echo $row_empresas_RS['E_nombre']?></option>
<?php
} while ($row_empresas_RS = mysql_fetch_assoc($empresas_RS));
$rows = mysql_num_rows($empresas_RS);
if($rows > 0) {
mysql_data_seek($empresas_RS, 0);
$row_empresas_RS = mysql_fetch_assoc($empresas_RS);
}
?>
</select>

This is fine, but I need the same select menu to insert also the value "id_E" (company id) depending on the company selected.

The select gets the values from a table that contains the columns "id_E" and "E_nombre". Both columns exist on the insertion table also.

 

Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/202505-help-with-select-values/
Share on other sites

Just change this line to

 

<option value="<?php echo $row_empresas_RS['id_E']."_".$row_empresas_RS['E_nombre']; ?>"><?php echo $row_empresas_RS['E_nombre']?></option>

 

Then where you do the insert into the database, you can get the two separate values with

 

$values = explode("_", $_POST['E_nombre']);

 

Then the id will be in $values[0] and the name in $values[1]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.