mysql_field_nameSynopsis
Descriptionmysql_field_name() fetches the name of a specified field in a result set. The field_offset argument specifies the desired field. The field offset starts at 0. If the field's value is generated by an expression, the expression is used as the name. For example, suppose this is the query: SELECT count(user); The name property would be count(user). If an alias is used for the column (or an expression), the alias is used as the name. For all other cases, the column name is used as the field name. ExampleExample 812. Show how mysql_field_name() behaves <?php // Included code that connects to a MySQL server and sets a default database // See the MySQL Functions chapter introduction for the source code for the file include ('mysql_connect.inc.php'); // A SELECT query using column names, aliases, and a few expressions $query = "SELECT login, login as alt_login, NOW()+0, UNIX_TIMESTAMP() as TS FROM user"; // Run the query $mysql_result = @ mysql_query ($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); // Loop through each field, grabbing the field names for ($offset = 0; $offset < mysql_num_fields ($mysql_result); ++$offset) { $field_names[] = mysql_field_name ($mysql_result, $offset); } // Display the field names echo "The field names from query <b>$query</b> are <b>:<ul><li>", join ('<li>', $field_names), '</ul>'; ?>
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|