Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section V: Using a Database > Lesson 23: Selecting Data

Lesson 23

Selecting Data

In this lesson you learn how to retrieve data from the database. The SELECT command is arguably the most common MySQL command you use in PHP programs. It is also one of the most complex, with clauses that enable you to choose what table(s) you use, which columns are returned, what conditions must be met before a row is selected, what order to sort the data in, and whether and how to group and summarize the data.

You work with a single table at a time in this lesson. In the next lesson you learn how to use multiple tables. The table used to illustrate this lesson is shown in Figure 23-1 and is created from the following code:

CREATE TABLE IF NOT EXISTS ‘table1’ (
  ‘id’ int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  ‘description’ text,
  ‘code’ int(11) NOT NULL DEFAULT ‘42’
) ENGINE=MyISAM;

INSERT INTO ‘table1’ (‘id’, ‘description’, ‘code’) VALUES
(101, ‘abc’, 99),
(102, ‘a’‘bc’, 15),
(103, ‘a’‘bc’, 15),
(104, ‘a’‘bc’, 15),
(105, ‘def’, 23),
(106, ‘ghi’, 23),
(107, ‘jkl’, 15),
(108, ‘mno’, 15),
(109, ‘pqr’, 23),
(110, ‘stu’, 42),
(111, ‘vwx’, 42),
(112, ‘yza’, 42),
(118, ‘efg’, 99);

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint