(2) Phạm Hữu Khang, Xây Dựng Ứng Dụng Web Bằng PHP & MySQL Tập 2 (2007) - NXB Phương Đông

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Editor : Pham Huu Khang

Editing: Phuong Lan

Web programming using PHP 5.3 and MySQL 5.1 database

Volume 2

Phuong Dong Publishing House

INTRODUCE

Following volume 1, volume 2 of the book "Web Programming with PHP 5.3 and MySQL 5.1
Database" includes 10 chapters and attached applications, respectively, introducing readers
to the knowledge related to Session, Cookie, online shopping cart, data search and
pagination, object-oriented programming and using Zend Framework.

Chapter 8 covers the basics of PHP server scripting and MySQL databases.

In chapter 9, you continue to learn how to design Web pages that allow users to search and
paginate data presented in a variety of formats.

To build a complete and highly professional e-commerce application, you continue to learn
how to use the Session and Cookie functions in chapter 10 to store user information for
resource management purposes. of the Website.

Every e-commerce application provides an online shopping cart chapter, you also learn how
to build a shopping cart using Session and Cookies in chapter 11.

When you need to present images, graphics, and sound as well as movies, you learn how to
use PHP code in chapter 12.

Next, you can learn the syntax of PHP scripting in chapter 13 and learn how to do object-
oriented programming and use this class in your application in chapter 14.

Chapter 15 helps you use Java Script client scripts to change the look and behaviour of
HTML tags in Web pages.

In Chapter 16 , you explore the open-source PHP library Zend for various types of
databases and learn how to use the classes in this library to sell online applications in
Chapter 17.
TABLE OF CONTENTS

INTRODUCE .................................................................................................................... 3

OPEN LETTER ................................................................................................................. 5

TABLE OF CONTENTS .................................................................................................... 7

Chapter 8: PHP Scenarios and MYSQL DATABASES .....................................................11

1. Database connection ...................................................................................................11

1.1 . Establish database connection .................................................................................12

1.2 . Open a database......................................................................................................13

1.3 . Database query .......................................................................................................17

2. List items......................................................................................................................17

2.1 . Number of items .......................................................................................................22

3. Add information to the database..................................................................................28

4. Update data .................................................................................................................33

5. Delete the items ...........................................................................................................38

6. Connect to another database .......................................................................................41

6.1 . PHP and Oracle Database .......................................................................................42

6.2 . PHP and the PostgreSQL database .........................................................................43

6.3 . PHP and MS SQL Server database .........................................................................45

7. End of Chapter .............................................................................................................46

Chapter 9: DATA SEARCH AND PAGINATION ...............................................................47

1. Data search function ....................................................................................................47

1.1 . Quick search ............................................................................................................48

1.2 . Basic search ............................................................................................................49

1.3 . Advanced search .....................................................................................................51

1.4 . Search Results .........................................................................................................53

2. List items by the group .................................................................................................60

3. Data navigation and pagination ....................................................................................63

3.1 . Query String and Paging Parameters .......................................................................63


3.2 . Search page with POST method ..............................................................................69

4. End of Chapter .............................................................................................................72

Chapter 10: SESSION AND COOKIE ..............................................................................73

1. Session concept...........................................................................................................73

2. Variable Session ..........................................................................................................74

2.1 . Session's life cycle ...................................................................................................74

2.2 . Session initialization declaration...............................................................................74

2.3 . Declare get value from Session................................................................................75

2.4 . Declare update value of Session ..............................................................................76

2.5 . Declare to delete Session ........................................................................................78

2.6 . Unique identifier of Session ......................................................................................79

2.7 . Application of the Session variable ...........................................................................81

3. Working with Cookie variables .....................................................................................86

3.1 . Create Cookie ..........................................................................................................87

3.2 . Get the value of Cookie ............................................................................................87

3.3 . Delete Cookies .........................................................................................................89

4. End of Chapter .............................................................................................................90

Chapter 11: CART AND ORDER ONLINE .......................................................................91

1. The concept of an online shopping cart ........................................................................91

2. Build a shopping cart....................................................................................................92

2.1 . Create and add new products to the cart ..................................................................95

2.2 . Update or add a new cart .........................................................................................96

2.3 . List shopping cart .....................................................................................................99

2.4 . Update the quantity ................................................................................................101

2.5. Delete cart...............................................................................................................104

2.6 . Cancel cart .............................................................................................................105

3. Order online ...............................................................................................................122

4. End of Chapter ...........................................................................................................122


Chapter 12: SPECIAL FUNCTIONS...............................................................................123

1. Send Email Using PHP Code .....................................................................................123

1.1 . About Email............................................................................................................123

1.2 . Build the function to send Email .............................................................................124

1.3 . Using the SendEmail function ................................................................................125

2. Upload files to the Web server ...................................................................................126

3. Insert music and movie apps......................................................................................130

4. Graphing in PHP ........................................................................................................133

5. Manage folders and files ............................................................................................137

5.1 . List directory listing .................................................................................................137

5.2 . Show file list ...........................................................................................................138

6. End of Chapter ...........................................................................................................140

Chapter 13: OBJECT ORGANIZED PROGRAMMING ...................................................141

1. Class and Object Concepts ........................................................................................141

2. Class declaration ......................................................................................................142

2.1 . Structure of the class .............................................................................................142

2.2 . Using class.............................................................................................................143

2.3 . Constructor ............................................................................................................146

3. Declare in the province ..............................................................................................150

4. Methods and parameters ...........................................................................................151

5. Inheritance declaration ...............................................................................................154

6. End of Chapter ...........................................................................................................158

Chapter 14: OBJECTIVE ORGANIZED APPLICATIONS TO THE WEBSITE ................159

1. Build a class that works with databases .....................................................................159

2. Declare using shared class ........................................................................................161

2.1 . Home page ............................................................................................................161

2.2 . Listing page............................................................................................................162

2.3 . Search page...........................................................................................................164


2.4 . Search results page ...............................................................................................166

2.5 . Account ..................................................................................................................168

2.6 . Order online ...........................................................................................................170

3. Building an object-oriented model ..............................................................................172

4. End of Chapter ...........................................................................................................175

Chapter 15: COMBINING JAVASCRIPT INTO PHP CODE ...........................................177

1. JavaScript code that references the HTML tag ..........................................................177

1.1 . Principles in JavaScript code..................................................................................178

1.2 . Reference to the HTML tag ....................................................................................180

2. Common Events in JavaScript ...................................................................................180

3. Commonly Used Functions in JavaScript ...................................................................182

4. Declare and Use Variables in JavaScript ...................................................................182

4.1 . Declare and use variables ......................................................................................182

4.2 . JavaScript Operations ............................................................................................182

5. JavaScript Controlled Statements ..............................................................................182

5.1 . The if statement .....................................................................................................183

5.2 If .. else statement ...................................................................................................183

5.3 . Statement while......................................................................................................183

5.4 . Statement for .........................................................................................................184

5.5 . Statement suitch .. case .........................................................................................184

5.6 . Break and continue statements ..............................................................................185

6. Data checking functions .............................................................................................185

6.1 . Use JavaScript for the <input> tag text and password ...........................................186

6.2 . JavaScript code and <input> tag radio ...................................................................188

6.3 . JavaScript code and <input> tag as checkbox .......................................................190

6.4 . JavaScript code and <select > tag .........................................................................191

6.5 . JavaScript code with <textarea> tag.......................................................................193

6.6 . JavaScript code with checkbox tag of the same name ...........................................196
7. JavaScript code with menu ........................................................................................203

7.1 . Build menu with <table > tag ..................................................................................203

7.2 . Build menus with tree span tags.............................................................................207

8. JavaScript code and popup window ...........................................................................209

9. JavaScript code to add and remove <select > tag elements.......................................211

10. Insert Javascript file .................................................................................................218

11. Combine JavaScript with PHP code .........................................................................224

12. End of Chapter .........................................................................................................230

Chapter 16: DISCOVER ZEND FRAMEWORK ..............................................................231

1. Introduction to Zend Framework.................................................................................233

2. Declare using layer in Zend Framework .....................................................................240

3. Presenting Data Using Zend Framework ....................................................................251

4. Add new items using Zend Framework ......................................................................254

5. Update items using Zend Framework .........................................................................258

6. Delete items with Zend Framework ............................................................................262

7. End of Chapter ...........................................................................................................263

Chapter 17: APPLICATION OF ZEND FRAMEWORK TO WEBSITE ............................263

1. How to use Zend Framework .....................................................................................263

2. Declare using Zend Framework's layer ......................................................................267

2.1 . Home page ............................................................................................................268

2.2 . The page lists the list of product types ...................................................................272

2.3 . Search page...........................................................................................................276

2.4 . Search results page ...............................................................................................281

2.5 . Account ..................................................................................................................285

2.6 . Order online ...........................................................................................................290

3. Chapter-ending ..........................................................................................................297

You might also like