从表中获取下拉列表的内容并将其存储在数组中

时间:2017-11-11 09:37:24

标签: php html mysql

我只想获取下拉列表的内容并将其存储在数组中。

我可以显示下拉列表,但它没有获取我选择的内容。

echo '<br><br><br><br><br>
    <div class="Table">
        <table border="2pt solid black" align="left" cellpadding="2px" bordercolor=black>
            <tr>
                <td width = "7%">
                    <div align = "left"><b>BRAND NAME</div></b>
                </td>
                <td width = "7%">
                    <div align = "left"><b>INGREDIENT</div></b>
                </td>
                <td width = "3%">
                    <div align = "left"><b>QUANTITY</div></b>
                </td>
                <td width = "7%">
                    <div align = "left"><b>MEASUREMENT</div></b>
                </td>
            </tr>';

for ($x = 0; $x < sizeof($rowarray); $x++) {
    $query = "select R.name AS RAWNAME, I.name AS INGREDIENTNAME, R.quantity AS RAWQUANTITY from rawmaterial R JOIN ingredient I ON R.ingredient_id = I.ingredient_id where R.rawmaterial_id='{$rowarray[$x]}'";
    $res = mysqli_query($dbc, $query);
    while ($fetch = mysqli_fetch_array($res, MYSQL_ASSOC)) {
        echo "<tr>
            <td width=\"7%\">
                <div align=\"left\">{$fetch['RAWNAME']}</div>
            </td>
            <td width=\"3%\">
                <div align=\"left\">{$fetch['INGREDIENTNAME']}</div>
            </td>
            <td width=\"3%\">
                <div align=\"left\"><input type='name' name='quantity[]' placeholder={$fetch['RAWQUANTITY']}></input></div>
            </td>
            <td width=\"7%\">
                <div align=\"left\">";
        echo "<select name = 'measure'>";
        $mesr = mysqli_query($dbc, 'select measure from measure_ref');
        while ($row = mysqli_fetch_array($mesr, MYSQLI_ASSOC)) {
            $mes = $row['measure'];
            echo '<option value ='.$mes.'>'.$mes.'</option>';
        }
        echo "</select>";
        echo "</div>";
        echo "</td>";
        echo "</tr>";   
    }       
}     

echo '</table></div>';
$messarray = array();
$mes = $_POST['measure'];
$row = array();
foreach ($mes as $row) {
    array_push($messarray, $row);
}

1 个答案:

答案 0 :(得分:0)

检查以下几点。

  1. 确保您的下拉列表在
  2. 范围内
  3. 当您创建多个下拉列表时,您应该使用&#39; []&#39;(measure [])命名,就像您已经提供了数量[]&#39;。