Jump to content

Recommended Posts

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 ...

 

 

Link to comment
https://forums.phpfreaks.com/topic/165371-solved-help-with-explode-and-implode/
Share on other sites

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>";

} ?>

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 ..

 

<!-- 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>";

} ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.