PHP mysql_result() 函数

定义和用法

mysql_result() 函数返回结果集中一个字段的值。

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

Syntax

mysql_result(data,row,field)
Parameters Description
data Required. Specify the result identifier to be used. This identifier is returned by the mysql_query() function.
row Required. Specify the row number. The row number starts from 0.
field

Optional. Specify which field to retrieve. It can be a field offset value, field name, or table.fieldname.

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

Description

When acting on a very large result set, consider using functions that can retrieve entire rows. These functions return multiple units of content in one function call, much faster than mysql_result().

In addition, please note that specifying a numeric offset in the field parameter is much faster than specifying a 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 Person";
$result = mysql_query($sql,$con);
echo mysql_result($result,0);
mysql_close($con);
?>

Output like:

Adams