retrive field names

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

retrive field names

Post by ddragas »

How to retrive all field names from db
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

desc %tablename%
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

Thnx for reply.

I think you didn't undersund my question.
What I want is to make loop and "echo" names of fields from table in db

| id | first_name | last_name | year_of_birth | etc |
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Burrito was right. "describe tablename" or "show columns in tablename" both work ...

Code: Select all

$conn = mysql_connect();

mysql_select_db();

$query = "show columns in tablename";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result))
{
    echo "$row[0]<br />\n";
}

mysql_close();
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you for reply.

I'll try that

It was my mistake. I dod not understand what Burrito was going to tell me. Sory Burrito and than you both
Post Reply