lingo5 Posted May 21, 2010 Share Posted May 21, 2010 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 More sharing options...
lingo5 Posted May 21, 2010 Author Share Posted May 21, 2010 Please...anyone? Link to comment https://forums.phpfreaks.com/topic/202505-help-with-select-values/#findComment-1061681 Share on other sites More sharing options...
MatthewJ Posted May 21, 2010 Share Posted May 21, 2010 Select menus allow for a single value on the option... you could probably do something like id_name for the value, then explode them on the _ to get both fields and insert them into the database... Link to comment https://forums.phpfreaks.com/topic/202505-help-with-select-values/#findComment-1061686 Share on other sites More sharing options...
lingo5 Posted May 21, 2010 Author Share Posted May 21, 2010 Thanks MatthewJ. I have no idea on how to do that. Could you please give me some code example. Thanks again Link to comment https://forums.phpfreaks.com/topic/202505-help-with-select-values/#findComment-1061690 Share on other sites More sharing options...
MatthewJ Posted May 22, 2010 Share Posted May 22, 2010 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] Link to comment https://forums.phpfreaks.com/topic/202505-help-with-select-values/#findComment-1061956 Share on other sites More sharing options...
lingo5 Posted May 22, 2010 Author Share Posted May 22, 2010 Thanks ever so much. Works like a dream!! Link to comment https://forums.phpfreaks.com/topic/202505-help-with-select-values/#findComment-1061959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.