Jump to content

display comma separated value from database in a drop down menu


jboy6t9

Recommended Posts

hello. i would love some help or someone to point me in the right direction.

I am building an ecommerce wesite selling clothes. i want to know if the following is possible.

For example, i have a product T-Shirt, that is available in RED,BLACK,BROWN and is availalbe in 4 sizes. Small, Medium, Large, X-Large.

I store it in the database using 4 fields, ID(1), ProductName (T-Shirt), Colors(RED,BLACK,BROWN), Sizes(Small, Medium, Large, X-Large), Price (12.00)

so now i create a PHP page that displays the product details. THIS IS WHERE I NEED THE HELP
[b]
I want to take the COLORS and SIZES and create drop down menu's with the data in the fields in the order they are typed.[/b]

can this be done? any ideas?
thanks in advance.
this may be help you. this create a combo. apply your option an send it to database as text.

<form name="form1" method="post" action="">
  <select name="select">
    <option>abc</option>
    <option>xyz</option>
  </select>
</form>
example of how to dynamically build a drop down, using your comma seperated string:

[code]
<?php

  $sql = "select * from table";
  $result = mysql_query($sql) or die(mysql_error());

  while ($list = mysql_fetch_assoc($result)) {
      echo "<select name = 'color'>";
      $colors = explode(',',$list['Colors']);
      foreach($colors as $c) {
        echo "<option value='$c'>$c</option>";
      } // end foreach color
      echo "</select>";
  } // end while
?>
[/code]

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.