MySQL Show Columns

The easiest way to get the column names of a MySQL table is the following:

SQL:
  1. SHOW COLUMNS FROM `table`

This will actually get you column/field names, type, key, null, extra and default values as well. A classic implementation of this would be to export a table to csv or something where you wanted to list the column names once at the top, then spin through the records and output them into a file.

PHP:
  1. $query = mysql_query("SHOW COLUMNS FROM `table`");
  2.  
  3. while($row = mysql_fetch_assoc($query)){
  4.    
  5.     echo $row['Field'].'<br>';
  6.    
  7. }

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • Reddit
  • Furl
  • NewsVine
  • Simpy
  • Slashdot
  • Spurl
  • StumbleUpon
  • YahooMyWeb
  • TailRank

Home | MySQL | MySQL Show Columns