Home >Backend Development >PHP Tutorial >Detailed explanation of how to use the mysql_result() function in PHP
This article mainly introduces how to use the PHP mysql_result() function. Friends who need it can refer to
mysql_result definition and usage
mysql_result() function return 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 the offset or field name of the field, or the field table point field name (tablename.fieldname). If a column is given an alias ('select foo as bar from...'), the alias is used instead of the column name.
If successful, the function returns the field value. If failed, returns false.
Calling mysql_result() cannot be mixed with other functions that process result sets.
Syntax
mysql_result(data,row,field)
Description | |
---|---|
Required. Specifies the result identifier to use. This identifier is returned by the mysql_query() function. | |
Required. Specify the line number. Line numbers start from 0. | |
Optional. Specifies which field to retrieve. Can be a field offset value, field name or table.fieldname. If this parameter is not specified, this function gets the first field from the specified row. |
mysql_result() .
<?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); ?>The output is similar: Adams
# replace mysql_result with mysqli in php The official method
Upgraded the php version today, and by the way, I want to change the mysql connection method in the php code to mysqli, because the official has been recommending mysqli and pdo since php5.3. Not much to say, just post the code// 错略的使用mysqli替换 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]; } }Related recommendations:
10 recommended articles about mysql_result()
Is there an alternative to mysql_result()
The above is the detailed content of Detailed explanation of how to use the mysql_result() function in PHP. For more information, please follow other related articles on the PHP Chinese website!