F
F
FlamyXD2018-05-23 21:26:11
MySQL
FlamyXD, 2018-05-23 21:26:11

How to join tables by column name?

To generate the form, I needed to create an SQL query that would return a similar result to me:
5b05b04525d30950688951.png
I think I need to start the query with:

SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'MYTABLENAME';

Which will return information about the table. Further, I don’t know how, but I need to connect this table and the query: I need the query to be universal for the table, the id field is in all tables.
SELECT * FROM `MYTABLENAME` WHERE id = 'MYID';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-05-23
@FlamyXD

Manually.
Store the result of the first query in an array of field descriptors.
Get from `MYTABLENAME` an associative array of values ​​like
['id' => ..., 'name' => ..., type => ..., 'displacement' => ..., 'construction_date' => . ..].
You go through the array of field descriptors, for each field you take the corresponding result from the array of values ​​and output it according to the type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question