Heya,
I know its a stupid question, but how would I list out all the column names I got from an sql query?
I need for instance
<name of column> <value of column>
ie
computer_name computer-1
computer_name computer-2
computer_name computer-3
Thanks!
Azh
How to get a list of column names from sql query
Moderator: General Moderators
-
jolan_lars
- Forum Newbie
- Posts: 19
- Joined: Thu Oct 23, 2003 12:15 pm
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Assuming that you used MySQL, if you've returned the result as an associative array (using [php_man]mysql_fetch_assoc[/php_man]()), you could do:
That's one way.
Mac
Code: Select all
while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $column_name => $column_value) {
echo $column_name.' '.$column_value.'<br />';
}
}Mac
Look here. It's almost exactly what you're asking for (I think).
http://ca.php.net/manual/en/function.my ... fields.php
http://ca.php.net/manual/en/function.my ... fields.php
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.