breaking a field into sections

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

breaking a field into sections

Post 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?
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post 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>
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

Thanks! It works just like i needed!
Post Reply