I have an assignment that I need to use a select tag to list three cities. I know how to code in html for a select tag.
This is what I have already working
Now what I need is the same results ^^ that gives you but by using a seperate .txt file for the cities. This is the code I have written. I know that the read file code is working fine. What I can't figure out is how to input the information in the select tag. I am sure, I am having a simple syntax issue but I really need to get this figured out.
Thanks for the help!
This is what I have already working
Code:
<select name="city" size="1">
<option value="0">-</option>
<option value="Chicago">Chicago</option>
<option value="Detroit">Detroit</option>
<option value="Toronto">Toronto</option>
</select>
Now what I need is the same results ^^ that gives you but by using a seperate .txt file for the cities. This is the code I have written. I know that the read file code is working fine. What I can't figure out is how to input the information in the select tag. I am sure, I am having a simple syntax issue but I really need to get this figured out.
Code:
$filename = 'data/'.'cities.txt';
$lines_in_file = count(file($filename));
$fp = fopen($filename, 'r');
for ($ii = 1; $ii <= $lines_in_file; $ii++)
{
$line = fgets($fp);
$city = trim($line);
print"<select size='1'>;
'$_POST['$city']';
</select>";
}
fclose($fp);
Thanks for the help!
Comment