In the application
PHP gets the mysql_result of the Display database data function ()
Mixed mysql_result (resource result_set, int row [, mixed field])
Gets the data for a field from the specified row in the Result_set. Simple but inefficient.
Example:
- $ Link1 = @mysql_connect ("Server1",
"WebUser", "password")
- Or Die ("Could not Connect
to MySQL server! ");
- @mysql_select_db ("Company")
Or Die ("Could not select database!");
- $ Query = "SELECT ID, Name
From product order by name ";
- $ result = mysql_query ($query);
- $ ID = Mysql_result ($result, 0, "id");
- $ name = Mysql_result ($result, 0, "name");
- Mysql_close ();
Note that the above code is only the field value of the first data in the output result set, and if you want to output all the records, you need to loop the processing.
- For ($i0<= mysql_num_rows ($result); $i + + )
- {
- $ ID mysql_result($result, 0, "id");
- $ name mysql_result($result, 0, "name");
- echo "Product: $name ($id)";
Note that if the query field name is an alias, the alias is used in Mysql_result.
PHP gets the mysql_fetch_row of the Display database data function ()
Array mysql_fetch_row (Resource result_set)
Gets the entire row from the Result_set and puts the data into the array.
Example (note and the smart fit of list):
- $ Query
Name from product order by name ";
- $ result mysql_query($query);
= Mysql_fetch_row ($result)) {
- echo "Product: $name ($id)";
PHP gets the mysql_fetch_array of the Display database data function ()
Array mysql_fetch_array (Resource result_set [, int result_type])
Enhanced version of Mysql_fetch_row ().
Gets each row of the Result_set as an associative array or/and a numeric index array.
By default, two arrays are obtained, result_type can be set:
MYSQL_ASSOC: Return associative array, field name = = Field value
Mysql_num: Returns an array of numeric indices.
Mysql_both: Gets the two arrays. Therefore each field can be referenced by index offset, or by field name.
Example:
- $ Query = "SELECT ID,
Name from product order by name ";
- $ result = mysql_query ($query);
- While ($row = mysql_fetch_array
($result, Mysql_both)) {
- $ name = $row [' name '];
- //or $ name = $row [1];
- $ name = $row [' id '];
- //or $ name = $row [0];
- echo "Product: $name ($id)";
- }
PHP gets the MYSQL_FETCH_ASSOC of the Display database data function ()
Array Mysql_fetch_assoc (Resource result_set)
Equivalent to Mysql_fetch_array ($result, MYSQL_ASSOC)
PHP gets the mysql_fetch_object of the Display database data function ()
Object Mysql_fetch_object (Resource Result_set)
As with the mysql_fetch_array () function, but instead of an array, an object is returned.
Example:
- $ Query = "SELECT ID, name
from product order by name" ;
- $ result = mysql_query ($query);
- while ($ row = mysql_fetch_object
($result)) {
- $ name = $row- > name;
- $ name = $row- > ID;
- echo "Product: $name ($id)";
- }
These functions are all summaries of PHP's access to the display database data functions.
http://www.bkjia.com/PHPjc/446138.html www.bkjia.com true http://www.bkjia.com/PHPjc/446138.html techarticle the mysql_result () mixed mysql_result (resource result_set, int row [, mixed field]) from Result_set is used to obtain the display database data function from the specified row Gets the number of a field ...