Does any one know how can I find the column name for a selected table in php?
Exmaple: If i have a table call customer as below:
cust_id cust_name cust_age
1 Alan 35
2 Alex 52
3 Amy 15
How can I get the column name only in php when I select customer table (which it will return me value are cust_id, cust_name and cust_age)?
If your database is MySQL then, you can use mysql_field_name() and mysql_fetch_field() function in php.
$res = mysql_query('select * from customer', $link);
echo mysql_field_name($res, 0); // print cust_id
echo mysql_field_name($res, 1); // print cust_name
echo mysql_field_name($res, 2); // print cust_age
You can check this http://php.net/manual/en/function.mysql-field-name.php
If you want other information for fields then check this out http://us2.php.net/manual/en/function.mysql-fetch-field.php
You can use SQL : SHOW COLUMNS FROM customer;
OR DESCRIBE customer;
SHOW COLUMNS or use the information_schema - the latter being more portable