Sigmahokies Posted March 19, 2021 Share Posted March 19, 2021 (edited) Hello everyone, I'm trying to get abbreviate states from plain text into HTML select and option, seem it's not working. Can you help me? here my PHP code: /* Read file to insert as option in HTML */ $file = fopen("States.txt","r") or exit("Unable to read"); while(!feof($file)) { $states = fgets($file); $statelist = "<option value='".$states."'>".$states."</option>"; } fclose($file); Then <tr><td>State:</td><td><select id="abb" name="abb"><?php echo $statelist ?></select></td></tr> Thank you for help Edited March 19, 2021 by Sigmahokies Link to comment Share on other sites More sharing options...
Ingolme Posted March 19, 2021 Share Posted March 19, 2021 I don't see anything obviously wrong with the code. Does the text file exist in the same folder as your PHP file? Link to comment Share on other sites More sharing options...
dsonesuk Posted March 20, 2021 Share Posted March 20, 2021 (edited) Apart from where it will only show the last option everytime. (.= required to append each option) $statelist .= "<option value='".$states."'>".$states."</option>"; Edited March 20, 2021 by dsonesuk 1 Link to comment Share on other sites More sharing options...
Sigmahokies Posted March 28, 2021 Author Share Posted March 28, 2021 dsonesuk, i forget to add .=, it showed now. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now