note 48269 added to function.mysql-field-name
| From: | colin dot truran at shiftf7 dot com | Date: | Fri, 17 Dec 2004 12:44:54 +0000 |
| Subject: | note 48269 added to function.mysql-field-name | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81906@lists.php.net to get a copy of this message | ||
T simply itterate through all the field names on a result set try using this.
$result = mysql_query($sql,$conn) or die(mysql_error());
$rowcount=mysql_num_rows($result);
$y=mysql_num_fields($result);
for ($x=0; $x<=$y; $x++) {
echo = mysql_field_name($result, $x).'<br>';
}
This is useful if you have a result set that joins several tables dynamicaly and you are never sure
what all the fields will be when you come to display them.
I suggest you place this within a loop through your result rows and include a field flag check
around the echo to only show certain data types like this.
$y=mysql_num_fields($result);
while ($row=mysql_fetch_array($result)) {
for ($x=0; $x<=$y; $x++) {
$fieldname=mysql_field_name($result,$x);
$fieldtype=mysql_field_type($result, $x);
if ($fieldtype=='string' && $row[$fieldname]!='')
echo $row[$fieldname].' , ';
}
echo '<br>';
}
----
Manual Page -- http://www.php.net/manual/en/function.mysql-field-name.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48269
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48269&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48269&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48269&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48269&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48269&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48269&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48269&report=yes
Search -- http://master.php.net/manage/user-notes.php