Jump to content

[SOLVED] Grab column names and values


therealwesfoster

Recommended Posts

I'm wanting to pull each column from 1 row and be able to list the column name and value on a page for editing.

 

So if I have a table called "users", and the columns:

id - name - email - pass

 

I want to be able to run a loop that will echo:

id > 1

name > Wes

email > [email protected]

pass > passwwoord

 

Make sense? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/
Share on other sites

  • 2 weeks later...

There is an even easier way, when you fetch a row (mysql_fetch_assoc), the keys in the resulting array will be the column names.

 

$row = mysql_fetch_assoc($result);
foreach($row as $key => $value) {
    echo "$key > $value<br />";
}

There is an even easier way, when you fetch a row (mysql_fetch_assoc), the keys in the resulting array will be the column names.

 

$row = mysql_fetch_assoc($result);
foreach($row as $key => $value) {
    echo "$key > $value<br />";
}

 

That's perfect bro. So simple too. :)

 

Wes

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.