W3Schools.com

PHP mysql_result() Function


PHP MySQL Reference 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:

Refsnes


PHP MySQL Reference Complete PHP MySQL Reference
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE