1

ドロップダウン リストにデータベースの値を入力したいと考えています。

<?php
require 'conn.php';

$filter=mysql_query("select distinct fuel_type from car");
while($row = mysql_fetch_array($filter)) {
$options ="<option>" . $row['fuel_type'] . "</option>";

$menu="<form id='filter' name='filter' method='post' action=''>
  <p><label>Filter</label></p>
    <select name='filter' id='filter'>
      " . $options . "
    </select>
</form>";

echo $menu;
}
?>

問題は、値が含まれる 1 つのリストではなく、2 つのリストを取得することです。お知らせ下さい

ドロップダウンリスト

4

3 に答える 3

2

echo $menu;ループの外にある必要があります。

于 2012-04-16T02:09:55.353 に答える
2

$menuをループから削除する必要があります。

<?php
require 'conn.php';

$options = '';
$filter=mysql_query("select distinct fuel_type from car");
while($row = mysql_fetch_array($filter)) {
    $options .="<option>" . $row['fuel_type'] . "</option>";
}

$menu="<form id='filter' name='filter' method='post' action=''>
  <p><label>Filter</label></p>
    <select name='filter' id='filter'>
      " . $options . "
    </select>
</form>";

echo $menu;

?>
于 2012-04-16T02:11:55.960 に答える
1
<?php
require 'conn.php';

$filter=mysql_query("select distinct fuel_type from car");
$menu="
<form id='filter' name='filter' method='post' action=''>
  <p><label>Filter</label></p>
    <select name='filter' id='filter'>";

// Add options to the drop down
while($row = mysql_fetch_array($filter))
{
  $menu .="<option>" . $row['fuel_type'] . "</option>";
}

// Close menu form
$menu = "</select></form>";

// Output it
echo $menu;
?>
于 2012-04-16T02:16:34.413 に答える