Home  >  Article  >  Backend Development  >  Detailed explanation of how to use the mysql_result() function in PHP

Detailed explanation of how to use the mysql_result() function in PHP

墨辰丷
墨辰丷Original
2018-05-17 14:09:442739browse

This article mainly introduces how to use the PHP mysql_result() function. Friends who need it can refer to

mysql_result definition and usage

mysql_result() function return 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 the offset or field name of the field, or the field table point field name (tablename.fieldname). If a column is given an alias ('select foo as bar from...'), the alias is used instead of the column name.

If successful, the function returns the field value. If failed, returns false.

Calling mysql_result() cannot be mixed with other functions that process result sets.

Syntax

mysql_result(data,row,field)


# #ParametersDescriptiondataRequired. Specifies the result identifier to use. This identifier is returned by the mysql_query() function. rowRequired. Specify the line number. Line numbers start from 0. field
Optional. Specifies which field to retrieve. Can be a field offset value, field name or table.fieldname.

If this parameter is not specified, this function gets the first field from the specified row.

Explanation

When working with large result sets, you should consider using a function that can retrieve the entire row. These functions return the contents of multiple units in one function call, which is much faster than

mysql_result() .

Also note that specifying a numeric offset in the field parameter is much faster than specifying the field name or tablename.fieldname.

Example

The output is similar:

Adams

# replace mysql_result with mysqli in php The official method

Upgraded the php version today, and by the way, I want to change the mysql connection method in the php code to mysqli, because the official has been recommending mysqli and pdo since php5.3. Not much to say, just post the code

// 错略的使用mysqli替换
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];
  }
}

Related recommendations:

10 recommended articles about mysql_result()

PHP’s mysql_result() function

Is there an alternative to mysql_result()

The above is the detailed content of Detailed explanation of how to use the mysql_result() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn