Name
mysql_result()
Synopsis
string mysql_result(results,row[,field|offset])
This function returns the data from one field of a
row from
results. Normally, this statement returns
the next row and can be reused to retrieve results sequentially. As a
third argument, you can give either a field name (i.e., the column or
alias name) or an offset to change the pointer for the function. This
function is typically used in conjunction with a loop statement to
process each field of a results set. Here is an example:
...
$sql_stmnt = "SELECT client_name FROM clients";
$results = mysql_query($sql_stmnt);
$num_rows = mysql_num_rows($results);
for ($index = 0; $index < $num_rows; $index++) {
print mysql_result($results, $index) . "\n";
}
...This script queries the database for a list of client names.
Using the mysql_num_row() function, the
number of rows contained in the results set is determined. Using that
bit of data, a for statement is constructed to loop
through the results set using mysql_result() to extract one
field of data per row. Otherwise, a function such as mysql_fetch_array() would have to
be used in conjunction with the usual method of retrieving data from
an array (e.g., $row[0]).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access