PHP & MySQL: How do I display a table from a query without hardcoding field names?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

adsmith82

Thread Starter
Joined
Jul 19, 2006
Messages
181
or rather how do i retrieve the field names after having selected a table
 
Joined
Nov 22, 2003
Messages
6,052
another possibility is this, it just popped in my head now so i havn't personally tried it, but I can't see any reason it wouldnt work

PHP:
$query = mysql_query("SELECT * FROM my_table");
while($row = mysql_fetch_array($query)){
echo "In this row...<br />";
foreach($row as $key=>$field)
echo $key." has a value of ".$field."<br />";
}
but if all you need is the names, not the data, then just use show columns
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top