Show column of mysql table

Let's say that you have a table with the following structure:

+--------------+----------+------+-----+---------+----------------+
| Field        | Type     | Null | Key | Default | Extra          |
+--------------+----------+------+-----+---------+----------------+
| Id           | int(11)  | NO   | PRI | NULL    | auto_increment |
| Author       | char(30) | NO   |     |         |                |
| Title        | char(100)| NO   |     |         |                |
| Summary      | text     | YES  |     |         |                |
| ISBN         | char(100)| YES  |     |         |                |
| Release_year | date     | NO   |     | 0       |                |
+--------------+----------+------+-----+---------+----------------+

and you want to list the column inside mysql and/or php code.

There are 2 mysql queries you do that: describe `table` and show columns from `table` where `table` must be replace with the name of the table.

Describe `table` provides information about the columns in a table. It is a shortcut for show columns from `table` and it does not have any conditions at all. As of MySQL 5.0.1, these statements also display information for views.

More information about the describe `table` can be found here: http://dev.mysql.com/doc/refman/5.0/en/describe.html.

The full syntax for show columns from `table` is:

SHOW [FULL] COLUMNS {FROM | IN} tbl_name [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]

Show columns displays information about the columns in a given table. It also works for views as of MySQL 5.0.1. The like clause, when it's present, indicates which column names to match. The where clause can be given to select rows using more general conditions.

For example, if you want to show only the column "release_year" you will use show columns from `table` like 'year.' You can use inside php like this:

$res = myql_query("show columns from `table` like 'year' ") or die(mysql_error());
$row = mysql_fetch_row($result);
 preg_match_all('/\'(.*?)\'/', $row[1], $enum_array);  if  (!empty($enum_array[1]))
 {
/* Shift array keys to match original enumerated index in MySQL (allows for use of index values instead of strings) */
foreach($enum_array[1] as $mkey => $mval)
$enum_fields[$mkey+1] = $mval;
return $enum_fields;
 }

More information about the show columns from `table` can found http://dev.mysql.com/doc/refman/5.0/en/show-columns.html

Related Articles

seo search engine optimisation The search engine optimisation part is very important for websites - they have to match certain criteria in order to appear as often as possible in the search results on Google and Bing. SEO (search engine optimization) starts from site / online store / platform development because it involves a specific structure of the pages, it involves an ease to browse for the visitors (for your clients) and it involves quicky loading when accessed. Our sites are delived already optimized, but if you have already a solution developed by someone else we analize your website and we offer consultancy - we'll tell you about the options you have about to boost its visibility and organic traffic.

realizăm site-uriWe develop websites to present your activity to the world and applications for internet that help you organize your activity as eficient as possible and without loses (in money, time and energy) wherever you are. Do you need an online store or a tool available for you anytime? We can develop that as long you reserve a domain name and some hosting space, the app is our job.

As an extension to your site or web app we can provide an app for your smartpone / table to keep you always informed about what's happening with the product already developed.

developing appsWe develop web applications and mobile apps (Android) for various companies and organisations according to their specifications and requirements. The apps are being used by employees and partners to work more efficient and with less costs for the company: the web applications can be accessed through the browsers installed on smartphones and tablets but the usage of a complementary mobile app can make efficiency to go up (it can increase the communication between people or it can show things not so important on PC).

We offer support for the applications used now and we develop them further using modern technologies.

Consulting bussiness online / itWe offer consultancy about the informatic system you have installed and we offer sollutions to make the more efficient, to improve and develop them further, we analize the activities inside your company and / organisation and we offer sollutions for the projects you want to develop.

If you don't have a website, an online store, a web application or a mobile app (Android) but you want to develop one for yourself or your company we offer the initial consultancy, the one that's necessary before starting anything about such project.

Share this URL on social social

"Cu capãtul arcurilor, trecînd,
rãzboinicii
mîngîie roua..."

Yosa Buson (1715-1783)

facebook sharing button
twitter sharing button
messenger sharing button
reddit sharing button
wordpress sharing button
whatsapp sharing button
tumblr sharing button
pinterest sharing button
blogger sharing button