M. Doe M. Doe - 1 month ago 9
PHP Question

HTML and PHP, filling a dropdown with lines from file

I have a file which currently contains


and I can't seem to find a way to read these from the file and then add each to my dropdown. The contents of the file are subject to change so I need to use a variable of some sort. I'm using php to read my file. I took a shot in the dark and tried

$j= 0;
echo'<b>Choose the reservation you would like to change </b>';
echo'<select name="change">';

while (!feof($fp))
echo'<option> $reservations[$j]</option>';
echo '</select>';

where $reservations[] already contains the file contents. it's echoing the html just fine, i'm just not filling the dropdown correctly.
any help is much appreciated!

$fp = fopen("reservations.txt", "r");

echo '<b>Choose the reservation you would like to change </b>';
echo '<p>';
echo '<select name="change">';

    $line = trim(fgets($fp));
    echo "<option>{$line}</option>";

echo '</select>';

Hope this code helps you!