使用多个值从数据库更新select标记

时间:2015-08-09 11:55:11

标签: php mysql select explode

我在数据库中有一个名为'item'的表,它有不同的列,其中一个名为'size'的表有两个以逗号分隔的值,即Medium,Large。现在,当我检索要在我的“选择”标签中显示的那些值时,它会一起显示它们,我尝试使用explode();但我搞砸了它的行为。我已将表格的图片和结果数据与代码一起附在我的网站上。

enter image description here

  

上面实现了while循环,这只是'Size:'部分

ID   Pay_ee  Pay_em Post
1    100      102   AE
1    105      112   RE
1    103      112   RE
1    106      123   RE
1    101      121   RE
1    109      143   AE
1    110      113   ME
1    115      132   RE
1    123      120   AE
1    100      120   AE
1    100      120   RE

enter image description here

1 个答案:

答案 0 :(得分:1)

爆炸后你需要遍历size数组。

    $arr = $row["item_size"];  
    $exp = explode("," , $arr);

echo "<select name='product_size'>";

foreach($exp as $key=>$val) {
        echo "<option value='" . $val . "'>" . $val . "</option>";
}

echo "</select>";

工作Demo

相关问题