簡體   English   中英

使用數組在PHP中填充下拉列表

[英]Populating Drop-Down in PHP using Array

我正在嘗試使用數組中的值填充下拉菜單。

我嘗試遵循其他答案,但是語法似乎不起作用。 (我對PHP還是比較陌生的)。

我正在處理的以下代碼是由其他人生成的。

$sqlite_query = "SELECT * FROM dis_kind";
$result = $db->query($sqlite_query);
$array = $result->fetchArray();

$output = "<select name=\"kind\" class=\"dis\" >\n";
$output .= "<option value=\"$this->wildcard_value\"></option>\n";

foreach ($result as $array) {
    $value = $array['kind'];
    $output .= "<option value=\"";
    $output .= $value;
    $output .= "\">";
    $output .= $value;
    $output .= " - ";
    $output .= $array['description'];
    $output .= "</option>\n";
}

$output .= "</select>\n";

我不知道為什么要按原樣進行,但是我對下拉菜單的使用感到沮喪。

當前,該框出現,但沒有任何值。

謝謝。

最終我自己解決了問題-在拔出頭發之前!

我沒有使用foreach循環,而是使用了以下內容:

while($array = $result->fetchArray()) 
{
    // Output code.
}

其中使用數組中的值填充了下拉菜單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM