php basics
PHP mysql_result function
The PHP mysql_result function is used to obtain MySQL result data. It is more suitable for processing where the amount of data is not too large. If the amount of data is large, other functions with better performance such as mysql_fetch_row and mysql_fetch_array should be used. mysql_result has been deprecated in PHP 5.5.0, replaced by mysqli_data_seek combined with mysqli_field_seek and mysqli_fetch_field.
PHP mysql_result function syntax
mixed mysql_result ( resource $result , int $row [, mixed $field ] )
mysql_result will return a string of the MySQL processing result, and FALSE if the processing fails.- resource $result: mysql_query processing result, necessary item.
- int $row-the number of rows to be retrieved (row number), row number starts from 0.
- mixed $field-the offset of the field, the default value is 0, not required.
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$sql = mysql_select_db('database_name');
$result = mysql_query('SELECT name FROM student');
echo mysql_result($result, 2);
?>
The example assumes that you want to retrieve the names of 3 students in the MySQL database, so the second parameter of mysql_result is set to 2, and the names of 3 students will be output.
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$sql = mysql_select_db('database_name');
$result = mysql_query('SELECT name FROM student');
echo mysql_result($result, 2);
?>
Post a Comment
0 Comments