0

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>";
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Roybut
0

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>";
0

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:

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.