# For Each Loop Using Comma Separated MYSQL cell

**URL:** <https://forum.kirupa.com/t/for-each-loop-using-comma-separated-mysql-cell/302670>\
**Category:** programming\
**Created:** [January 5, 2010, 4:10pm UTC](https://forum.kirupa.com/t/for-each-loop-using-comma-separated-mysql-cell/302670 "2010-01-05T16:10:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michistar](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@michistar](https://forum.kirupa.com/u/michistar)\
**Post date:** [January 5, 2010, 4:10pm UTC](https://forum.kirupa.com/t/for-each-loop-using-comma-separated-mysql-cell/302670/1 "2010-01-05T16:10:51Z")

</div>

Hey everyone,

Kinda stuck on this problem and was hoping I could get some help. Basically I’m trying to use an array & for each loop to output data from a comma separate cell inside a database into a drop down menu.

I pulled the code from a tutorial site. It works fine when I’m using a normal array, however when I pull the data from the database, it outputs everything onto the same line. I’ve posted everything below.

This is the code I pulled from the tutorial… it works correctly.

```auto

    $browsers = array ("Firefox", "Internet Explorer", "Opera");
    echo "<select>";
    foreach($browsers as $browser) 
    {
        echo "<option name='$browser'>$browser</option>";
    }
    echo "</select>";

```

It outputs this:  
 ![](http://forum.kirupa.com/uploads/kirupa/6077/a8f250d8cfd16a0c.jpg)

When I use the same code w/ the database code, it outputs this.

![](http://forum.kirupa.com/uploads/kirupa/6078/42fb2a049a5f2cb4.jpg)

Instead of outputting them as separate options like above.

Here is the code that isn’t outputting incorrectly:

```auto

$info = mysql_fetch_array( $data ); 
$ctop = $info['color'];
$list4array = $ctop;
$array2 = array($list4array);
    $newlist = array ($list4array);
    echo "<select>";
    foreach($newlist as $work) 
    {
        echo "<option name='$work'>$work</option>";
    }
    echo "</select>";

```

The data saved inside the cell is formated as follows: ‘red’,‘blue’,‘green’

Thanks in advance for any help that anyone can provide 🙂 I’m really hoping that it’s just a simple solution being overlooked.

Thanks again.
