Is is possible to create a select menu in HTML from a CSV file? I have no idea how to go about this.
So I have a CSV that has two columns and multiple values, is there any way I can loop through the CSV file with PHP and output HTML, I have tried this so far.
$row = 1;
if (($handle = fopen($_SERVER['DOCUMENT_ROOT']."/service/regions.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 133, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
echo "<option value='".$data[$c]."'>".$data[$c]."</option>";
}
}
fclose($handle);
}
However this is giving the following output,
<select>
<option value='AB'>AB</option>
<option value='Aberdeenshire'>Aberdeenshire</option>
<option value='AG'>AG</option>
<option value='Angus'>Angus</option>
<option value='AM'>AM</option>
<option value='Armagh'>Armagh</option>
</select>
What I am wanting is to get the output like this,
<option value="AB">Aberdeenshire</option>
Where am i going wrong?