note 81672 added to function.mysql-field-name
| From: | anonymous at site dot com | Date: | Sun, 09 Mar 2008 14:13:04 +0000 |
| Subject: | note 81672 added to function.mysql-field-name | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136864@lists.php.net to get a copy of this message | ||
This function is slightly stupid to be honest, why not just make an array of field names... You
could consolidate the two of these functions that way and it makes it a lot easier to list them when
your script is dynamic.
<?php
function mysql_field_array( $query ) {
$field = mysql_num_fields( $query );
for ( $i = 0; $i < $field; $i++ ) {
$names[] = mysql_field_name( $query, $i );
}
return $names;
}
// Examples of use
$fields = mysql_field_array( $query );
// Show name of column 3
echo $fields[3];
// Show them all
echo implode( ', ', $fields[3] );
// Count them - easy equivelant to 'mysql_num_fields'
echo count( $fields );
?>
----
Server IP: 92.48.74.199
Probable Submitter: 77.99.239.47
----
Manual Page -- http://www.php.net/manual/en/function.mysql-field-name.php
Edit -- https://master.php.net/note/edit/81672
Del: integrated -- https://master.php.net/note/delete/81672/integrated
Del: useless -- https://master.php.net/note/delete/81672/useless
Del: bad code -- https://master.php.net/note/delete/81672/bad+code
Del: spam -- https://master.php.net/note/delete/81672/spam
Del: non-english -- https://master.php.net/note/delete/81672/non-english
Del: in docs -- https://master.php.net/note/delete/81672/in+docs
Del: other reasons-- https://master.php.net/note/delete/81672
Reject -- https://master.php.net/note/reject/81672
Search -- https://master.php.net/manage/user-notes.php