PHP : mysql_result() function
has average rating
7
out of 10.
Total 4 users rated.
Description
The mysql_result() is used to fetch the contents of a single field from a mysql query.
Version
(PHP 4 and above)
Syntax
mysql_result (result, row, field)
Parameters
| Name | Description | Required/ Optional | Type |
|---|---|---|---|
| result | Refers to the resource return by a valid mysql query (calling by mysql_query()). | Required | Resource |
| row | The row number from the result that's being retrieved. Row numbers start at 0. | Required | Integer |
| field | The name or position of the field being retrieved. | Optional | Mixed* |
*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.
Return value
The contents of one field from a MySQL result set on success, or FALSE on failure.
Value Type : String.
Example :
<?php
$con = mysql_connect("localhost", "root", "mypass");
$selectdb = mysql_select_db("tutorials",$con);
$result = mysql_query("select name from tutorials");
$no_result = mysql_num_rows($result);
echo "<h2>Here is a list of the topics :</h2>";
for ($i=0;$i<=$no_result;$i++)
{
echo "<p>".mysql_result($result,$i)."</p>";
}
mysql_close($con);
?>
Output :
Here is a list of the topics :
html
css
sql
mysql
javascript
php
See also

