For Each Loop Using Comma Separated MYSQL cell

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.


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

It outputs this:

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

Instead of outputting them as separate options like above.

Here is the code that isn’t outputting incorrectly:


$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 :slight_smile: I’m really hoping that it’s just a simple solution being overlooked.

Thanks again.