Hi,

I'm trying to create a database that stores shoes. Each shoe must have more than one size so I have created a table "mens_boot_test" with a field "size". In the size field I have an integer which holds the delimited values 1,2,3,4,5,6,7,8,9. I'm then trying to retrieve these values in a drop down box but they are all coming up as one option instead of nine.

Can someone please tell me what I am doing wrong?

$query  = "SELECT * FROM boot_mens_test where id = 7";
$result = mysql_query($query);
echo "<form name='sizetest'><select name='Sizes'>";



while($row = mysql_fetch_array($result))
{
    echo "<option value='{$row['size']}'>{$row['size']}</option>";
}


echo "</form>";

is this how your table looks like ?

id size
7 1,2,3,4,5,6,7,8,9

then your code would need to be like this:

$query  = "SELECT * FROM boot_mens_test where id = 7";
$result = mysql_query($query);
echo "<form name='sizetest'><select name='Sizes'>";
if ($row = mysql_fetch_array($result))
{
    $sizes = explode(',', $row['size']);
    foreach ($sizes as $size)
        echo "<option value='$size'>$size</option>";
}
echo "</select></form>";

is this how your table looks like ?

id size
7 1,2,3,4,5,6,7,8,9

then your code would need to be like this:

$query  = "SELECT * FROM boot_mens_test where id = 7";
$result = mysql_query($query);
echo "<form name='sizetest'><select name='Sizes'>";
if ($row = mysql_fetch_array($result))
{
    $sizes = explode(',', $row['size']);
    foreach ($sizes as $size)
        echo "<option value='$size'>$size</option>";
}
echo "</select></form>";

Hi,

Yes, you got the table right. That did exactly what I was looking for. I did try using explode but couldn't get that to work either. Thanks very much for the help:icon_biggrin:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.