0

How can i display a columns values from my database in a drop down menu as selections? So far I have the forms code down I think now I'm trying to figure out the actual database code side of this. Any help is greatly appreciated. Thanks in advance.

This may help:

http://oi61.tinypic.com/258tmhd.jpg

CODE

<html>
<header>



</header>

<body>

<form action="/demoform/contact_form.php" id="formA" method="post" name="formA">

<big>LOAD PAST ORDERS:</big>

<select id="drop_down" name="drop_down">
   <?php foreach($array_results as $row) : ?>
       <option value="<?php echo $row['key'];?>" ><?php echo $row['itemname'];</option>
   <?php endforeach; ?>
</select>



<input type="text" id="email" name="email"/>



<input id="email" name="email" type="text"   value="demo@gmail.com" readonly="readonly"/>


<input id="itemname" name="itemname" type="text" />



<button type="submit" value="Submit">Submit</button>


</form>


</body>


</html>
Steve Brown
  • 115
  • 2
  • 11

1 Answers1

0

If you use PHP mysqli OOP this is hopefully helpful:

while($row = $result->fetch_array()) {
 echo("<option value=\"" . $row["key"] . "\">" . $row["itemname"] . "</option>\n");
}

To fill the input text field with the value of the dropdown you can use jQuery:

<script type="text/javascript">
$("#idOfDropDown").change(function() {
 $("#idOfTextField").val( $("#idOfDropDown option:selected").val() );
});
</script>