Click here to Skip to main content
15,918,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>
Posted
Updated 6-Apr-16 0:36am
Comments
Mohibur Rashid 18-Sep-14 23:02pm    
Your question does not make any sense. I would ask you to explain what 'use same drop down list in html form'. You already have used it in a form. What else are you trying to do?

1 solution

mysql_connect("localhost","root") or die("not conected");
mysql_select_db("db_resolve") or die("not find the db");
$output = '';
//Logic Part
if(isset($_POST['search']))
{
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM scrb WHERE district LIKE '%$searchq%' OR PS_SCRB LIKE '%$searchq%' OR Supplier LIKE '%$searchq%'") or die("could not search!");
$count = mysql_num_rows($query);
if($count == 0)
{
$output = 'there was no search results!';
}
else
{
while($row = mysql_fetch_array($query))
{
$dist = $row['District'];
$ps = $row['PS_SCRB'];
$supl = $row['Supplier'];
$cntc = $row['Contact'];
$mob = $row['Mobile'];


$output .= '
'.$dist.' - '.$ps.' - '.$supl.' - '.$cntc.' - '.$mob.'
';
}
}
}
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900