dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: List fields in a table

  1. #1
    Join Date
    Oct 2005
    Posts
    593

    List fields in a table

    Hi there,

    Does anyone know how i can list all the NAMES of the fields in a table in my SQL database?

    Scott

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Use:
    SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE 'pattern']

    It will return a record set, one row for each field in the table, with name, field type, Null-Yes/No, Key type, default value and additional attributes.

  3. #3
    Join Date
    Oct 2005
    Posts
    593
    Way, i never knew about the show function... Been making a few little scripts for my site now! Thanks very much for that.. In one of my scripts im trying to echo all of the tables in my DB into a drop down menu... "SHOW tables"

    Id normally do this my something like echo $row['rowname']; but i cant do that here...

    How would i go about doing that?

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Yes, you can... almost.

    Since you don't know the column name - there's only one - you use mysql_fetch_array() as usual, but instead of echo $row['colname'], use echo $row[0].

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles