Help adding a pulldown box that pulls from PHP array to form. I have created a h
ID: 3760913 • Letter: H
Question
Help adding a pulldown box that pulls from PHP array to form. I have created a hard coded version below. Basically I need this to happen by using a php array to pull the states from, and populate my pull down menu.
I have created a form to ask the viewer to select a state that will then post to my server via action= (this part works fine). I have created it "hardcoded" in the example below, but I need that row in my form to pull from a PHP array, and basically do the same as what I hardcoded.
<!--
<tr><td>
<label for="state">State: </label></td>
<td>
<select name="state" id="state">
<option value="Select Desired State">Select Desired State</option>
<option value="Georgia">Georgia</option>
<option value="Alabama">Alabama</option>
<option value="Flordia">Florida</option>
</select>
</td></tr>
//-->
Explanation / Answer
<!--
<tr>
<td>
<label for="state">State: </label>
</td>
<td>
<select name="state" id="state">
<option value="Select Desired State">Select Desired State</option>
<option value="Georgia">Georgia</option>
<option value="Alabama">Alabama</option>
<option value="Flordia">Florida</option>
<?php
$names = array("Georgia", "Alabama", "Florida");
foreach($names as $name) {
?>
<option value="<?php echo $name; ?>">
<?php echo $name; ?> </option>
<?php
}
?>
</select>
</td></tr>
-->
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.