How to use PHP to associate an array query result. You may have specific operation code for the following :? Php $ connectionmysql_connect (localhost, albert, shhh); mysql_select_db (winestore, $ connection); $ resultmysql_qu You MayThe specific operation code is as follows:
- php
- $connection = mysql_connect("localhost", "albert", "shhh");
- mysql_select_db("winestore", $connection);
-
- $result = mysql_query("SELECT cust_id, surname,
- firstname FROM customer", $connection);
-
- while ($row = mysql_fetch_array($result))
- {
- echo "ID:t{$row["cust_id"]}n";
- echo "Surnamet{$row["surname"]}n";
- echo "First name:t{$row["firstname"]}nn";
- }
- ?>
The mysql_fetch_array () function puts a row of the query result into an array and can be referenced in two ways at the same time. for example, cust_id can be referenced in the following two ways at the same time: $ row ["cust_id"] or $ row [0]. Obviously, the former is much more readable than the latter.
In the multi-table join query of PHP joined array query results, if the two columns have the same name, it is best to separate them with aliases:
SELECT winery. name AS wname,
Region. name AS rname,
FROM winery, region
WHERE winery. region_id = region. region_id;
The column names are referenced as $ row ["wname"] and $ row ["rname"].
When the table name and column name are specified, only the column name is referenced:
SELECT winery. region_id
FROM winery
Column name reference: $ row ["region_id"].
The reference of the aggregate function is the reference name:
SELECT count (*)
FROM customer;
Column name reference: $ row ["count (*)"].
The above are all the specific operations on the PHP associated array query results.
The specific operation code is as follows :? Php $ connection = mysql_connect ("localhost", "albert", "shhh"); mysql_select_db ("winestore", $ connection); $ result = mysql_qu...