SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: get field names from table?

  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get field names from table?

    what is the query to get all the field names of a table?

    I am trying to create an array in PHP to hold the field names of a perticular table.

    Thanks!
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    reads the ********* Crier silver trophybronze trophy SitePoint Award Recipient longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    describe tablename

  3. #3
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    describe tablename
    OK say I have a database

    on this database I have a table named products

    the products table as an uncertain ammount of fields in it (ie: 'name', 'price', 'description') I need to get a list of all of those fields??

    THanks.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  4. #4
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out....

    PHP Code:
    $all_rows = array();
    $sql "SHOW COLUMNS FROM `product`";
    $result mysql_query($sql);
    while (
    $row mysql_fetch_assoc($result)){
        
    array_push($all_rows,$row['Field']);

    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by halfasleeps View Post
    OK say I have a database

    on this database I have a table named products

    the products table as an uncertain ammount of fields in it (ie: 'name', 'price', 'description') I need to get a list of all of those fields??

    THanks.
    He was giving you the answer DESCRIBE is a MySQL command. It describes the table definition.
    17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
    Conversion tracking, click fraud detection, A/B testing and more.

  6. #6
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    He was giving you the answer DESCRIBE is a MySQL command. It describes the table definition.
    Ohh hahaha....I was wondering how could he know the answer if he needed me to describe what a table was lol

    Thanks.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  7. #7
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,456
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by halfasleeps View Post
    Quote (longneck):
    describe tablename
    OK say I have a database

    on this database I have ...


    i had a real strong hunch that was gonna happen

    i would at least have used code tags and italics:
    Code:
    describe tablename
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    reads the ********* Crier silver trophybronze trophy SitePoint Award Recipient longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, both commands are easily available in the mysql manual. i had to make the poster at least work a little bit.

Bookmarks

Posting Permissions

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