imarockstar Posted July 9, 2009 Share Posted July 9, 2009 I have an array stored in a DB such as this 1,2,3,4,5 and I explode it to be placed in a drop down. This works great. However I need to explode another field from the DB to also be inserted ... the use ... I need to pull the OPTION - > Name, and also the OPTION - > Value, and have them dynamically displayed. I do this because I have over 100 questions in this form. below is a the code that I use to explode the data. Does anyone know how I can also explode another array and also use it to populate the VALUE portion of this drop down ? <!-- displays a DROPDOWN if it is one --> <?php if ( $rows['gq_type'] == 2 ) { $a = explode(',', $rows['emp_options']); echo "<select class='FMselect' name=' " .$rows['emp_id']." '>"; echo "<option>Please Choose</option>"; foreach ($a as $v) { echo "<option>" . $v . "</option>"; } echo "</select>"; } ?> you can see I am exploding - > $rows['emp_options'] and this is being inserted as the option NAME I need - > $rows['emp_options'], exploded and inserted as the value ... but I am not sure on how to do this ... Quote Link to comment https://forums.phpfreaks.com/topic/165371-solved-help-with-explode-and-implode/ Share on other sites More sharing options...
.josh Posted July 9, 2009 Share Posted July 9, 2009 You mean like this? <!-- displays a DROPDOWN if it is one --> <?php if ( $rows['gq_type'] == 2 ) { $a = explode(',', $rows['emp_options']); echo "<select class='FMselect' name=' " .$rows['emp_id']." '>"; echo "<option>Please Choose</option>"; foreach ($a as $v) { echo "<option value='$v'>" . $v . "</option>"; } echo "</select>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165371-solved-help-with-explode-and-implode/#findComment-872110 Share on other sites More sharing options...
imarockstar Posted July 9, 2009 Author Share Posted July 9, 2009 oh crap I am an idiot .. please ... I miss typed ... I meant this ... you can see I am exploding - > $rows['emp_options'] and this is being inserted as the option NAME I need - > $rows['emp_options_value'], exploded and inserted as the value ... but I am not sure on how to do this ... the value is different then the option name ... so I need to expload these 2 fields from the DB .. $rows['emp_options'] and $rows['emp_options_value'] sorry for the typo .. Quote Link to comment https://forums.phpfreaks.com/topic/165371-solved-help-with-explode-and-implode/#findComment-872117 Share on other sites More sharing options...
.josh Posted July 9, 2009 Share Posted July 9, 2009 <!-- displays a DROPDOWN if it is one --> <?php if ( $rows['gq_type'] == 2 ) { $a = explode(',', $rows['emp_options']); $b = explode(',', $rows['emp_options_value']); echo "<select class='FMselect' name=' " .$rows['emp_id']." '>"; echo "<option>Please Choose</option>"; foreach ($a as $k => $v) { echo "<option value='{$b[$k]}'>" . $v . "</option>"; } echo "</select>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165371-solved-help-with-explode-and-implode/#findComment-872119 Share on other sites More sharing options...
imarockstar Posted July 9, 2009 Author Share Posted July 9, 2009 if it was really that easy .. im going to shoot myself in the foot .. haha ok i will try that ... thx Quote Link to comment https://forums.phpfreaks.com/topic/165371-solved-help-with-explode-and-implode/#findComment-872124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.