Results 1 to 3 of 3

Thread: put table field names into an array

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    put table field names into an array

    I am using PHP with a MySQL database.

    I am wondering if it's possible to get the field names of a table dynamically and put them into an array? I would also be nice to dynamically get a list of tables in the database also. So if a table is added or a field is added I don't have to change my code.

    In VBScript you can do a recordset(iFieldPosition).Name and get the name of the field.

    Currently the only why I have seen in php is to hardcode the field name you want to work with. Example:
    while ($row = mysql_fetch_array($sql_result)) {
    $variable1 = $row["FIELD1"];
    $variable2 = $row["FIELD2"];
    }

    Thanks in advance for your help.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    It'd do you wonders to check out the manual at www.php.netwww.php.net, specifically http://www.php.net/manual/en/ref.mysql.php.

    Check out these functions mysql_list_fields(), mysql_list_tables(), and mysql_list_dbs().
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yes you can. to get the tables it is

    mysql_table_list() I believe, then you have to search for the field names.

    $local_query = "SHOW FIELDS FROM " . $table);

    jsu tlike that

Posting Permissions

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



Click Here to Expand Forum to Full Width