Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: list all fields

  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    list all fields

    Hi

    I'm looking for a script to list all fields in mysql database table, can someone show me a typical code or a link where I can get such info.
    Regards JD

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you use phpmyadmin, you can view the data dictionary which shows you that information. it is at the bottom of the table list in the right-hand frame.

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just run this query

    Code:
    SHOW COLUMNS
    FROM
     tablename
    The column names will be returned in a column called 'Field':

    PHP Code:
    while( $row mysql_fetch_assoc($result) )
    {
      echo 
    $row['Field'];


  • #4
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    mysql_connect
    ("localhost""root""psswd");
    mysql_select_db("database");
    $result mysql_query("SHOW COLUMNS FROM table");

    while(
    $field mysql_fetch_array($result)){
       echo 
    $field[Field];
       echo 
    "<br />";
    }

    ?>
    EDIT: Wups, Kid Charming beat me to it


  •  

    Posting Permissions

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