therealwesfoster Posted September 19, 2008 Share Posted September 19, 2008 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 > bla@sl.com pass > passwwoord Make sense? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/ Share on other sites More sharing options...
fenway Posted September 29, 2008 Share Posted September 29, 2008 "For editing" is a php issue... does the mysql query pull the desired rows? Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/#findComment-653272 Share on other sites More sharing options...
therealwesfoster Posted September 29, 2008 Author Share Posted September 29, 2008 Not needing the editing part, I can do that. I just need help on the query and how to loop it all. A simple example would work Wes Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/#findComment-653454 Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2008 Share Posted September 29, 2008 There are at least two mysql_field_xxxxxx functions listed in the php manual that will give you field (column) names. Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/#findComment-653456 Share on other sites More sharing options...
therealwesfoster Posted September 29, 2008 Author Share Posted September 29, 2008 There are at least two mysql_field_xxxxxx functions listed in the php manual that will give you field (column) names. Thanks. Yeah, I just need an example on using them. Wes Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/#findComment-653464 Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2008 Share Posted September 29, 2008 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 />"; } Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/#findComment-653469 Share on other sites More sharing options...
therealwesfoster Posted September 29, 2008 Author Share Posted September 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124965-solved-grab-column-names-and-values/#findComment-653471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.