mazman13 Posted October 24, 2007 Share Posted October 24, 2007 Trying to make a drop down box like this example: Dog Cat Bird But sometimes I will need to update it...and add/remove names from the list. I want to do it fast and easy and I don't want to use a MySQL Database. I'd rather use a text file...can that be done? I would keep the info in a text file and then push it to a drop down box via php and html. Let me know if this will work. Quote Link to comment https://forums.phpfreaks.com/topic/74614-solved-need-to-create-drop-down-box-with-data-pulled-from-text-file/ Share on other sites More sharing options...
enoyhs Posted October 24, 2007 Share Posted October 24, 2007 Yes it will work. Code would be something like this: $text = file_get_contents("test.txt"); $array = explode("\n",$text); echo "<select>"; foreach ($array as $value) { echo "<option value='$value'>$value</option>"; } echo "</select>"; Quote Link to comment https://forums.phpfreaks.com/topic/74614-solved-need-to-create-drop-down-box-with-data-pulled-from-text-file/#findComment-377136 Share on other sites More sharing options...
mazman13 Posted October 24, 2007 Author Share Posted October 24, 2007 I figured it might. What do I need to do in the txt file to make it work? Quote Link to comment https://forums.phpfreaks.com/topic/74614-solved-need-to-create-drop-down-box-with-data-pulled-from-text-file/#findComment-377137 Share on other sites More sharing options...
enoyhs Posted October 24, 2007 Share Posted October 24, 2007 Look at my specified code above. Options will be separated by enter (or if you want other separator just change "\n" to whatever value you want in explode("\n",$text) Quote Link to comment https://forums.phpfreaks.com/topic/74614-solved-need-to-create-drop-down-box-with-data-pulled-from-text-file/#findComment-377142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.