1

I was wondering if there was a way to make a select box with multiple options based on one row from my MySQL table.

For instance,

<?php 

            if(!empty($row['size']))
            { ?>
                <label>Size</label>
                <select name="size">
                <option value=""><?php echo $row['size'];?></option>
                </select>

            <?php

            }


        ?>

in my database I have one row labeled "size". In that row, I have multiple sizes separated by a coma. Is it possible to break those comas into separate options once I retrieve the data from my table? Or will I have to make multiple rows in my DB labeled "size_1, size_2".... and so on.

Kevin1990M
  • 53
  • 8
  • usually it is a bad idea to store multiple pieces of information in 1 field. Only when it is information you never need seperately, like a config or so. – Ivo P Jul 04 '17 at 00:12
  • As Ivo says, a design decision like this is really bad because it violates the [Zero, One or Infinity Rule](http://en.wikipedia.org/wiki/Zero_one_infinity_rule) of proper [database normalization](http://en.wikipedia.org/wiki/Database_normalization). A relational database likes to have relationships expressed as table-to-table links, one column value to one other column value to relate rows. Having multiple values in one column impairs that. – tadman Jul 04 '17 at 02:25
  • If that record has many sizes, make some table that includes all the sizes and reference that somehow. Maybe you have multiple attributes and each product refers to one set of those. The exact solution depends on your requirements, but comma-separated values are trouble. – tadman Jul 04 '17 at 02:26

1 Answers1

0

I want to link to this question right here

The coding-stuff for your question:

foreach ($_GET['size'] as $selectedOption)
echo $selectedOption."\n";
Kaan2106
  • 100
  • 11