How to use PHP to join the array query result _ PHP Tutorial

Source: Internet
Author: User
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:

 
 
  1. php
  2. $connection = mysql_connect("localhost", "albert", "shhh");
  3. mysql_select_db("winestore", $connection);
  4. $result = mysql_query("SELECT cust_id, surname,
  5. firstname FROM customer", $connection);
  6. while ($row = mysql_fetch_array($result))
  7. {
  8. echo "ID:t{$row["cust_id"]}n";
  9. echo "Surnamet{$row["surname"]}n";
  10. echo "First name:t{$row["firstname"]}nn";
  11. }
  12. ?>

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.