I am creating a website using PHP and MYSQL which has 3 pages; Insert, Update & Delete. The insert page adds a new column to a database table. In my update page I want to be able to view all data which is in the table where the new column has been added. How would I go about this? i.e if theres now 11 columns after the insert rather that 10 previous i want the update page to show
col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9 | col10 | col11
data | data | data | data | data | data | data | data | data | data | data
Even adding columns (altering procedure) from PHP is bad practice for me, there might be different solution. You can retrieve the columns from information_schema:
Also for actual result, you can name them "col1, col2", so you can iterate through the results and recieve variable like
Then you can recieve results for every column, also their names.
Here's an example with a table of mine:
Output:
That's without knowing the column names and their count. It's enough they have the same prefix "col".
After adding one new column:
The same code (without any change) produces:
P.S.: I'm still not encouraging this table structuring, where you need to add columns dynamicly