You are here: Home Development PHP PHP: Display Row (Field) Names in MySQL Database Table
PHP: Display Row (Field) Names in MySQL Database Table PDF Print E-mail
User Rating: / 3
PoorBest 
Development - PHP
Written by Rick   
Monday, 14 July 2008 17:00

On occassion we need to get the Row names in a table. The following code snippet shows how to connect to the database and display all the Row names in the database table.

 $con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
    mysql_select_db(DB_NAME, $con);
    $sql="Select * FROM DB_TABLENAME";
    $result = mysql_query($sql,$con) or die(mysql_error());

    $rowcount=mysql_num_rows($result);
    $y=mysql_num_fields($result);
        for ($x=0; $x<$y; $x++) {
               echo mysql_field_name($result, $x).'<br>';
        }

    mysql_close($con);

 

Comments (0)
Write comment
Your Contact Details:
Gravatar enabled
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):S
:!::?::idea::arrow:
Security
Please input the anti-spam code that you can read in the image.