PHP mysql_result() Function
Definition and Usage
The mysql_result() function returns the value of a field from a result set.
If successful, the function returns the field value. If it fails, it returns false.
Syntax
mysql_result(data,row,field)
Parameters | Description |
---|---|
data | Required. Specifies the result identifier to be used. This identifier is returned by the mysql_query() function. |
row | Required. Specifies the row number. The row number starts from 0. |
field |
Optional. Specifies 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 a single function call, much faster than mysql_result().
Additionally, 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 similar to:
Adams