PHP mysql_result() Function
Complete PHP MySQL Reference
Definition and Usage
The mysql_result() function returns the value of a field in a recordset.
This function returns the field value on success, or FALSE on
failure.
Syntax
mysql_result(data,row,field)
|
Parameter |
Description |
data |
Required. Specifies which result handle to use. The data
pointer is the return from the mysql_query() function |
row |
Required. Specifies which row number to get. Row numbers
start at 0 |
field |
Optional. Specifies which field to get. Can be field
offset, field name or table.fieldname. If this parameter is not defined
mysql_result() gets the first field from the specified row |
Tips and Notes
Note: This function is slower than mysql_fetch_row(),
mysql_fetch_array(), mysql_fetch_assoc() and mysql_fetch_object().
Note: This function should not be used together with mysql_fetch_row(),
mysql_fetch_array(), mysql_fetch_assoc() or mysql_fetch_object().
Example
<?php
$con = mysql_connect("localhost", "peter", "abc123");
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);
?>
|
The output of the code above could be:
Complete PHP MySQL Reference
|
|
|