How to use PHP associative array query Results _php tutorial

Source: Internet
Author: User
You may be rightHere is the specific operation code:

 
 
  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 function mysql_fetch_array () puts a row of query results into an array, which can be referenced in both ways, for example cust_id can be used in the following two ways: $row ["cust_id"] or $row[0]. Obviously, the former is much more readable than the latter.

In the case of multiple-table links in the query results of the PHP associative array, if the two column names are the same, 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 referred to as: $row ["Wname"] and $row ["Rname"].


In the case of specifying table and column names, only column names are referenced:

SELECT winery.region_id
From Winery

The reference to the column name is: $row ["region_id"].

A reference to a clustered function is the reference name:

SELECT COUNT (*)
from customer;

The reference to the column name is: $row ["Count (*)"].

These are all the specific steps for the query results of the PHP associative array.


http://www.bkjia.com/PHPjc/446371.html www.bkjia.com true http://www.bkjia.com/PHPjc/446371.html techarticle you may be to the following is the specific operation code:? 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.