Dynamic HTML drop-down with PHP and MySQL

Joshua Otwell
6 min readMay 6, 2020

After spending a great deal of time in my day job developing a web reporting dashboard/interface with PHP and MySQL, I feel that I have found my stride in back-end web development with PHP. Learning to develop web applications using the LAMP stack — or one of its derivatives (E.g., WordPress, CodeIgniter, Laravel, etc..) — is a huge focus for me right now. It’s no secret I am a MySQL fanatic — hence this blog — and have written about Python code along with the MySQL Shell a great deal here. However, as it normally goes for developers, the PHP/MySQL back-end web development has inspired me to, of course, start a side project. Go figure right! What developer doesn’t have a side project, or two? Be on notice that you will see more and more PHP/MySQL and LAMP-stack related posts in the future, in addition to the MySQL posts I regularly publish. In the meantime, I’ll share something super neat o (to me at least) I learned while working on my side project. I’m sure it is simple and standard for seasoned web developers, but sparks that exciting, exploratory learning feel for me. Continue reading to see more…

Photo by Jakob Owens on Unsplash

Self-Promotion:

If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!

Choices. Everyone likes choices right? Can there be choices in an HTML web form? Yes, there can, by using the select element. How about one that is dynamically populated with PHP based on available data from a MySQL database? That is a resounding yes as well.

I have a ‘shoes_worn’ MySQL table that stores various shoes I wear — or have worn — on daily walks and hikes:

Current table data for export…

I created this simple form to capture walking stats (E.g., distance, time, pace, etc…) I am going to store in the database. Instead of entering in a shoe name or shoe id number by hand, I would rather have a drop-down of the available data from the ‘shoes_worn’ table. Just as important, should I: add another row, update a row, or remove any rows from the ‘shoes_worn’ table, the drop-down…

Joshua Otwell

SQL, PHP, CodeIgniter, and WordPress. Growing through Technical Writing and Blogging. Sign-up for my free developer newsletter here: openlamptech.substack.com