从数据库中检索数据并以下拉格式显示。并使用相同的下拉列表作为输入。
问题描述:
我遇到了以下问题。我能够从数据库中检索数据并将其显示在下拉菜单中。但我不知道如何使用相同的下拉列表作为输入并将其嵌入到表单中我的代码如下。这些项目名称是从数据库中检索出来的,并以下拉列表的形式显示。现在我需要在表格(HTML表格)中使用相同的下拉列表,用于输入数据到另一张桌子。
i have been having the following problem .I am able to retrieve the data from database and display it in a drop down menu.But i dont know how to use the same drop down list as the input and embed it in a form.My code is as follows.Here project names are retrieved from the database and are displayed in the form of drop down list.Now i need to use the same drop down list in the form(HTML form) which will be used to input data into another table.
<html>
<head></head>
<body>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include 'connect.php' ;
$tbl_name="projects";
$sql="SELECT project_name FROM $tbl_name ";
$result=mysql_query($sql);
if($result === FALSE) {
die(mysql_error());
}
?>
<form name="resources" action="hourssubmit.php" method="post" >
<?php
echo "<select name='project_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['project_name'] ."'>" . $row['project_name']."</option>";
}
echo "</select>";
?>
</form>
</body>
</html>
答
tbl_name =projects;
tbl_name="projects";
sql =SELECT project_name FROM
sql="SELECT project_name FROM
tbl_name;
tbl_name ";