Jump to content

[SOLVED] help with EXPLODE and IMPLODE ...


imarockstar

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

} ?>

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.