Page 1 of 1

breaking a field into sections

Posted: Thu Oct 03, 2002 12:50 pm
by Zoram
I am trying to generate a drop down menu for my products page on a website.

What I want to do is make it so that if the $colors = "Yellow, Green, Blue" then php will go through and every time there is a comma it will write the color into an array which can be used to make a dropdown menu.

Any Help?

Posted: Thu Oct 03, 2002 4:45 pm
by mr_griff
Try this:

Code: Select all

<?php
$colors = "Yellow,Green,Blue";
$colorArray = explode(",",$colors);
?>
<select name="color">
  <?php
  while (list($index,$color) = each ($colorArray)) 
  &#123;
    echo "<option value="$color">$color</option>"; 
  &#125;
  ?>
</select>

Posted: Thu Oct 03, 2002 5:51 pm
by Zoram
Thanks! It works just like i needed!