How to use the mysql_result () function in PHP

Source: Internet
Author: User
Tags field table
This article mainly introduces the PHP mysql_result () function use method, the need for friends can refer to the following

Mysql_result Definition and usage

The mysql_result () function returns the value of a field in the result set.

Mysql_result () returns the contents of a cell in the MySQL result set. The field parameter can be either the offset of the field or the field name, or the Field table Point field name (Tablename.fieldname). If the column is aliased (' select Foo as bar from ... '), the column name is replaced with an alias.

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

Calling mysql_result () cannot be mixed with other functions that process the result set.

Grammar

Mysql_result (Data,row,field)


Parameters Description
Data Necessary. Specifies the result identifier to use. The identifier is returned by the mysql_query () function.
Row Necessary. Specifies the line number. The line number starts at 0.
Field

Optional. Specifies which field to get. Can be a field offset value, field name, or Table.fieldname.

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

Description

When used as a large result set, you should consider using functions that can take the entire row. These functions return the contents of multiple cells in a single function call, mysql_result() much faster.

Also note that specifying a numeric offset in the field parameter is much faster than specifying the 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"; $result = mysql_query ($sql, $con); Echo MySQL _result ($result, 0); Mysql_close ($con);? >

The output is similar to:

Adams

The official method of replacing Mysql_result in PHP mysqli

The PHP version is upgraded today, and by the way, the MySQL connection in PHP code is changed to Mysqli, since the official php5.3 has been recommending Mysqli and PDO since the beginning of the day. No more talking, sticker code.

Use mysqli to replace if (!function_exists (' mysql_result ')) {  function mysql_result ($result, $number, $field =0) {    Mysqli_data_seek ($result, $number);    $row = Mysqli_fetch_array ($result);    return $row [$field];  }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.