#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Columbus, OH 43212
    Posts
    4
    Rep Power
    0
    I'm trying to simply list the names of fields within a certain table. On another page I figured out how to list the available tables within a database, using the list_tables & table_name, so I figured I could do the same using the list_fields & field_name - but it doesn't seem to be working. If anyone could please correct the code I have so far, or give another example of how to achieve this I would be greatful - for I am still a novice at this whole game

    Code so far: (works with table list/name)

    <?

    $connect = mysql_connect("localhost","login","pass");

    $result = mysql_list_fields($db,"tablename");
    $i = 0;
    while ($i < mysql_fetch_array($result)) {
    $tb_names[$i] = mysql_field_name($result, $i);

    echo "$tb_names[$i]<br>";

    $i++;

    Thanks a lot to all that can help.
    ~Moog

    }

    ?>

    ------------------
    ---
    Thanks.
    ~Moog

    http://www.moogman.com
    http://www.caveradio.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    This will list all the fields in your table.

    $dbhost = "localhost";
    $dbuser = "";
    $dbpass = "";
    $dbname = "";
    $dbtable = "";


    if (!($db = mysql_connect($dbhost, $dbuser, $dbpass))) echo "error connecting to ". $dbname ."on ". $dbhost;
    mysql_select_db($dbname,$db);

    $result = mysql_list_fields($dbname, $dbtable);

    for ($i=0 ; $i<mysql_num_fields($result); $i++) {
    $field = mysql_field_name($result,$i);
    print $field;
    }

Similar Threads

  1. dynamic form field names
    By harwoodspike in forum PHP Development
    Replies: 1
    Last Post: February 1st, 2004, 10:43 AM
  2. does anyone know how to edit access field names?
    By Roaster in forum Visual Basic Programming
    Replies: 9
    Last Post: December 16th, 2003, 06:39 PM
  3. Display MySQL field names in HTML
    By cranfordio in forum PHP Development
    Replies: 5
    Last Post: December 15th, 2003, 11:29 AM
  4. Addressing multi-word field names in MySQL
    By slipnfall in forum PHP Development
    Replies: 2
    Last Post: November 21st, 2003, 10:22 AM
  5. Addressing multi-word field names in PHP
    By slipnfall in forum MySQL Help
    Replies: 0
    Last Post: November 21st, 2003, 08:56 AM

IMN logo majestic logo threadwatch logo seochat tools logo