I’m not new to PHP and MySQL, but I’m not professional in it.
I have a mysql database table related to program settings.
Thirty cities, each of which has fifteen items, and every day these items must be reviewed by the user and, if necessary, changed and saved. Like the picture below:
I can make a table with a div and put an input in each cell, read the information from the database and display it to the user and save it in the database after the change.
But I feel that this method of mine may work, but it is not professional at all.
My question is, what is the best way to do this, especially if I want the names of the cities and their items to be assigned by the program to each of the input boxes, so that if the city name changes in the database, there is no need to change the program code.
Footnote: The language used is PHP and the names of the cities and their items in the image are hypothetical and the names are not in sequence.
I appreciate your help in advance.
2
Answers
@Karl Hill Thank you for ur response, the first row data from table is:
how to get the items name and province name?
You can create a dynamic form based on the data from your database. This way, if the city names or items change in the database, your form will automatically reflect these changes without needing to modify your code.
Here’s a basic example of how you can do this in PHP:
In this code,
mysqli_query
is used to fetch the data from the database. Then, awhile
loop is used to iterate over the data and create an input field for each row. Theid
andname
attributes of the input fields are set to the city and item names, and thevalue
attribute is set to the current value. This creates a dynamic form based on the data in your database.When the form is submitted, you can then process the form data and update the database accordingly. Note that you’ll need to replace
your_table
andyour_action_page.php
with your actual table name and form action page.