Ahmad Budi U Ahmad Budi U - 5 months ago 9
MySQL Question

SOLVED - How to show column names of multiple table in mysql

I have 2 tables

person
and
country
. Table
person
has 3 columns
id_person
,
name_person
and
id_country
.
country
has 2 columns
id_country
and
name_country
.

I want to show "name_person" and "name_country", just the name of column, not record. How can I get this ?

[SOLVED] I'm using mysql_fetch_field bellow the query

Answer

You can access table columns in MySQL's information schema database:

SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_NAME` IN ('country', 'person')
    AND `COLUMN_NAME` LIKE 'name_%';
Comments