This article mainly introduces the PHP mysql_result () function use method, the need for friends can refer to the following
Mysql_result Definition and usage
The mysql_result () function returns the value of a field in the result set.
Mysql_result () returns the contents of a cell in the MySQL result set. The field parameter can be either the offset of the field or the field name, or the Field table Point field name (Tablename.fieldname). If the column is aliased (' select Foo as bar from ... '), the column name is replaced with an alias.
If successful, the function returns the field value. If it fails, it returns false.
Calling mysql_result () cannot be mixed with other functions that process the result set.
Grammar
Mysql_result (Data,row,field)
Parameters |
Description |
Data |
Necessary. Specifies the result identifier to use. The identifier is returned by the mysql_query () function. |
Row |
Necessary. Specifies the line number. The line number starts at 0. |
Field |
Optional. Specifies which field to get. Can be a field offset value, field name, or Table.fieldname. If this parameter is not specified, the function gets the first field from the specified row. |
Description
When used as a large result set, you should consider using functions that can take the entire row. These functions return the contents of multiple cells in a single function call, mysql_result()
much faster.
Also note that specifying a numeric offset in the field parameter is much faster than specifying the field name or Tablename.fieldname.
Example
<?php$con = mysql_connect ("localhost", "Hello", "321"), if (! $con) {die (' Could not connect: '. Mysql_error ());} $db _selected = mysql_select_db ("test_db", $con); $sql = "select * from"; $result = mysql_query ($sql, $con); Echo MySQL _result ($result, 0); Mysql_close ($con);? >
The output is similar to:
Adams
The official method of replacing Mysql_result in PHP mysqli
The PHP version is upgraded today, and by the way, the MySQL connection in PHP code is changed to Mysqli, since the official php5.3 has been recommending Mysqli and PDO since the beginning of the day. No more talking, sticker code.
Use mysqli to replace if (!function_exists (' mysql_result ')) { function mysql_result ($result, $number, $field =0) { Mysqli_data_seek ($result, $number); $row = Mysqli_fetch_array ($result); return $row [$field]; }}