I'm not sure what you want the final result to look like.
The metadata table information_schema.columns
, though, can help you. This will give you a mapping from the column position (ordinal_position
) and the column name (column_name
) for each table.
In php, you can access the data for a column by position. You can then look up the column name for that position in that table . . . and do what you want with it.
For instance, you could take all the possible column names for a set of such tables and create the code for a view for them. Something like:
create view vw_AllQuestions as (
select <column list> -- with NULL values for the columns not in TableA
from tableA
union all
select <column list> -- with NULL values for the columns not in TableB
from tableB
. . .
);