0

我创建了以下代码,它使下拉列表能够从 sql db 中获取所有值,它能够获取数字但不显示..

    <?php
$link = mysql_connect('www.xxxxxxxx.com', 'xxxxxxx', 'xxxxxxx');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxxxxxxxxxxxxxx", $link);

function print_dropdown($query)
{
$queried = mysql_query($query);
$menu = '<select name="Topic">';
while ($result = mysql_fetch_array($queried)) {
$menu .= '
<option value="' . $result['topic'] .'</option>';
}
$menu .= '</select>';
return $menu;
}


echo print_dropdown("SELECT topic FROM learning_outcome");
?>

但输出似乎是空的.. :(

4

1 回答 1

5
$menu .= '<option value="' . $result['topic'] .'</option>';

应该是这样的:

$topic = htmlspecialchars($result['topic']);
$menu .= '<option value="' . $topic .'">' . $topic . '</option>';
于 2012-06-24T04:39:43.360 回答