需要一些建议。
我想在网站上包含 4 个下拉列表,它们都包含来自 mysql 表中不同字段的数据。
然后我希望能够按下提交按钮并在网页上显示所需的数据。
我不知道要使用哪种编程语言,也很难找到任何教程。任何帮助将不胜感激。
谢谢
您的意思是 HTML 下拉列表还是表单中的选择下拉列表?
如果您的意思是表单中的选择下拉菜单,您可以执行以下操作:
<?PHP
$query = mysql_query("SELECT value FROM table ORDER BY value ASC") or die(mysql_error());
$result = mysql_num_rows($result);
// If no results have been found or when table is empty?
if ($result == 0) {
echo 'No results have been found.';
} else {
// Display form
echo '<form name="form" method="post" action="your_result.php">';
echo '<select name="list" id="lists">';
// Fetch results from database and list in the select box
while ($fetch = mysql_fetch_assoc($query)) {
echo '<option id="'.$fetch['value'].'">'.$fetch['value'].'</option>';
}
echo '</select>';
echo '</form>';
}
?>
然后在 your_result.php 中,您应该根据以下值从 MySQL 数据库中获取数据(当您获取时使用 mysql_real_escape_string):
<?PHP $_POST['list']; ?>
您也可以在一个文件中完成所有操作,但这取决于您。尝试使用谷歌,那里有几十个教程。