SCHOOL OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY
TEXTBOOK MODULE: WEB DESIGN AND PROGRAMMING
Author: Doan Phuoc Mien
Pham Thi Truc Mai
Tra Vinh, 04/2014
For internal circulation only
Tài liệu giảng dạy môn …………………………….
Table of contents CHAPTER 1 ............................................................................................................... 1 HYPERTEXT MARKUP LANGUAGE (HTML LANGUAGE) ............................. 1 LESSON 1 .................................................................................................................. 1 OVERVIEW OF INTERNET, WEB AND WEB DESIGN ...................................... 1 1.1.1 History of the Internet and the Web .................................................................. 1 1.1.2 Basics concept on the Internet and the Web ...................................................... 2 1.1.3 Basic services on the Internet ............................................................................ 4 1.1.4 How the activity of a Website ........................................................................... 5 1.1.5 HTML Page Structure ....................................................................................... 6 LESSON 2 .................................................................................................................. 9 BASIC HTML CARDS .............................................................................................. 9 1.2.1 <body> tags, note and special symbols ............................................................. 9 1.2.2 Text formatting tags......................................................................................... 10 1.2.2.1 The <div> … </div> . tag ............................................................................. 10 1.2.2.2 The <p> … </p> . tag ................................................................................... 11 1.2.2.3 Title formatting tags ..................................................................................... 12 1.2.2.4 Text formatting tags ..................................................................................... 13 1.2.2.5 <marquee> tag ............................................................................................. 15 1.2.3 List Format Cards ............................................................................................ 17 1.2.3.1 Unordered List <ul> ..................................................................................... 17 1.2.3.2 Ordered list ................................................................................................... 18 1.2.4 Cards to insert images and sounds................................................................... 20 LESSON 3 ................................................................................................................ 27 SUPER LINKS AND FRAME ................................................................................ 27 1.3.1 Hyperlink – Hyperlink ..................................................................................... 27 1.3.1.1 Internal Links ................................................................................................ 28 1.3.1.2 External links ................................................................................................ 30 1.3.2 Frame – frame .................................................................................................. 32 1.3.2.1 The <frameset> … </frameset> . tag ........................................................... 32 1.3.2.2 The <noframe> … </noframe> . tag ............................................................ 36 1.3.2.3 The <iframe> … </iframe> . tag .................................................................. 37 LESSON 4 ................................................................................................................ 44 TABLES ON WEB .................................................................................................. 44 1.4.1 Creating a table ................................................................................................ 44 1.4.2 Table Format Properties .................................................................................. 44 1.4.2.1 Attributes in the <table> . table tag .............................................................. 44 1.4.2.2 Attribute in <tr> . line tag ............................................................................. 45 1.4.2.3 Attributes in <th>, <td> . cell/column tags .................................................. 46 1.4.3 Web interface design using <table> ................................................................ 48 LESSON 5 ................................................................................................................ 58 FORM AND CONTROLS ....................................................................................... 58 1.5.1 Meaning of the form in the Web page and how to create it ............................ 58 1.5.2 Form components ............................................................................................ 58 1.5.2.1 <input> . tag.................................................................................................. 59 1.5.2.2 The <textarea> … </textarea> . tag.............................................................. 62 1.5.2.3 <select> … </select> . tag ............................................................................ 62 1.5.2.4 The <fieldset> … </fieldset> . tag ............................................................... 63 1.5.2.5 Summary table of components in the form .................................................. 68 CHAPTER 2 ............................................................................................................. 77 SUPPLY SAMPLE TABLE – CSS ......................................................................... 77 2.1 Cascading Style Sheet concept ........................................................................... 77 2.2 Classification ...................................................................................................... 78 2.2.1 Inline style sheet .............................................................................................. 79 2.2.2 Internal style sheet ........................................................................................... 80 2.2.3 External style sheet .......................................................................................... 82 2.3 Applying CSS to interface design ...................................................................... 83 2.3.1 Selector ............................................................................................................ 83 2.3.2 Common CSS properties in interface design .................................................. 84 CHAPTER 3 ............................................................................................................. 98 JAVASCRIPT LANGUAGE ................................................................................... 98 3.1 Introduction ........................................................................................................ 98 3.2 Variables, operators, operands, constants, functions, commands in JavaScript 99 3.2.1 Variables in JavaScript .................................................................................... 99 3.2.2 Operator ......................................................................................................... 101 3.2.3 Constants ....................................................................................................... 102 3.2.4 Functions ....................................................................................................... 102 3.2.5 Controls in JavaScript .................................................................................... 105 3.2.5.1 Conditional statements if / if … else .......................................................... 105 3.2.5.2 Switch selection…case ............................................................................... 106 3.2.5.3 for loop ....................................................................................................... 107 3.2.5.4 The for… in loop ....................................................................................... 108 3.2.5.5 while loop .................................................................................................. 109 3.2.5.6 Do… while loop ......................................................................................... 109 3.2.6 References to Objects in HTML.................................................................... 110 3.2.6.1 Reference to the value of the card .............................................................. 110 3.2.6.2 Reference to the length of the tag ............................................................... 111 3.2.6.3 Reference to the state of the card ............................................................... 111 3.2.6.4 Some methods............................................................................................. 112 3.2.6.5 Manipulating the ID of the HTML tag ....................................................... 112 3.2.7 Using some objects ........................................................................................ 112 3.2.7.1 String Object .............................................................................................. 113 3.2.7.2 Date object .................................................................................................. 113 3.2.7.3 Array Object .............................................................................................. 114 3.2.7.4 Math object ................................................................................................. 115 CHAPTER 4 ........................................................................................................... 123 PHP OVERVIEW................................................................................................... 123 LESSON 1 .............................................................................................................. 123 INTRODUCING PHP ............................................................................................ 123 4.1.1. What is PHP? ................................................................................................ 123 4.1.2. History of PHP development ........................................................................ 123 4.1.3. Advantages and disadvantages of PHP ........................................................ 124 4.1.3.1. Advantages ................................................................................................ 124 4.1.3.2. Defect......................................................................................................... 125 4.1.4. Active mechanism of Web dynamic............................................................. 125 LESSON 2 .............................................................................................................. 127 ABOUT AND INSTALL WEBSERVER .............................................................. 127 4.2.1 Introducing WebServer ................................................................................. 127 4.2.2. Install WampServer2 .................................................................................... 128 4.2.3. Using WampServer2 .................................................................................... 135 CHAPTER 5 ........................................................................................................... 138 PHP BASIC FEMALE ........................................................................................... 138 LESSON 1 .............................................................................................................. 138 CONVENTIONS AND DECLARATION............................................................. 138 5.1.1. Conventions in PHP...................................................................................... 138 5.1.2. Variables in PHP .......................................................................................... 139 5.1.4.1 How to declare variables ............................................................................ 139 5.1.4.2 PHP Built-in Variables ............................................................................... 140 5.1.4.3 Variable scope in PHP page ....................................................................... 140 5.1.3. Data types in PHP ......................................................................................... 141 5.1.4. Operator ........................................................................................................ 141 5.1.4.1 Operators on strings (string) ....................................................................... 141 5.1.4.2 Operators on arithmetic .............................................................................. 142 5.1.4.3 Assignment operators ................................................................................. 142 5.1.4.4 Comparison operators ................................................................................. 143 5.1.4.5 Logical operators ........................................................................................ 143 LESSON 2 .............................................................................................................. 144 CONDITIONAL PROCESSES AND INSTALLATION STRUCTURE ............. 144 5.2.1 Conditional clause ......................................................................................... 144 5.2.1.1 The if clause............................................................................................... 144 5.2.1.2 If… else clause ........................................................................................... 144 5.2.1.3 The if…elseif…else clause......................................................................... 145 5.2.1.4 Switch clause .............................................................................................. 145 5.2.2 Looping Structure .......................................................................................... 145 5.2.2.1 The while structure ..................................................................................... 145 5.2.2.2 Structure do…while .................................................................................... 146 5.2.2.3 The for structure ......................................................................................... 147 5.2.2.4 The foreach structure .................................................................................. 147 LESSON 3 .............................................................................................................. 150 FUNCTIONS IN PHP ............................................................................................ 150 5.3.1 Some commonly used built-in functions ....................................................... 150 5.3.1.1 Some string handling functions .................................................................. 150 5.3.1.2 Some functions to handle date and time ..................................................... 151 5.3.1.3 Some mathematical functions..................................................................... 154 5.3.2 User-defined functions .................................................................................. 155 5.3.2.1 Syntax ......................................................................................................... 155 5.3.2.2 Using the function ...................................................................................... 155 5.3.2.3 Value and parameter ................................................................................... 156 5.3.3 Reusing PHP Code ........................................................................................ 156 5.3.4 Files in PHP ................................................................................................... 158 5.3.4.1 Open files .................................................................................................... 159 5.3.4.2 Close files ................................................................................................... 160 5.3.4.3 Reading and writing files in PHP ............................................................... 160 5.3.4.4 Checking end of file ................................................................................... 161 5.3.5 Object Class .................................................................................................. 163 5.3.5.1. How to declare ........................................................................................... 163 5.3.5.2. How to use..... ............................................................................................ 164 LESSON 4 .............................................................................................................. 166 HANDLING FORM VALUE IN PHP................................................................... 166 5.4.1. GET method ................................................................................................. 167 5.4.2. POST method ............................................................................................... 167 LESSON 5 .............................................................................................................. 169 PHP COOKIE AND SESSION BASICS ............................................................... 169 5.5.1. Cookies Overview ........................................................................................ 170 5.5.1.1. Set up cookies ............................................................................................ 170 5.5.1.2. Use cookies ................................................................................................ 171 5.5.1.3. Cancel Cookies .......................................................................................... 171 5.5.2. Session overview .......................................................................................... 171 5.5.2.1. Set up the session ....................................................................................... 171 5.5.2.2. Using the value of the session ................................................................... 172 5.5.2.3. Cancel session............................................................................................ 173 CHAPTER 6 ........................................................................................................... 174 PHP & MYSQL74 .................................................................................................. 174 LESSON 1 .............................................................................................................. 174 OPERATION ON MYSQL DATABASES ........................................................... 174 6.1.1. Introduce ....................................................................................................... 174 6.1.2. Characteristics .............................................................................................. 174 6.1.2.1. Create Database ......................................................................................... 175 6.1.2.2. Delete Database ......................................................................................... 176 6.1.2.3. Manipulating tables in MySQL ................................................................. 176 6.1.2.4. Import and export data ............................................................................... 181 LESSON 2 .............................................................................................................. 183 CONNECT TO MYSQL DATABASES ............................................................... 183 6.2.1. Steps to build a program that connects to the Database ............................... 183 6.2.2. Error message ............................................................................................... 183 LESSON 3 .............................................................................................................. 186 OPERATION ON MYSQL DATABASES WITH PHP ....................................... 187 6.3.1. Count the number of records ........................................................................ 187 6.3.2. Data display .................................................................................................. 187 6.3.3. Save new information to the database .......................................................... 193 6.3.4. Updating data ................................................................................................ 194 6.3.5. Delete data .................................................................................................... 194 CHAPTER 7 ........................................................................................................... 196 COMPLETE A SITE .............................................................................................. 196 7.1 Requests ............................................................................................................ 196 7.2 Analysis ............................................................................................................ 199 7.1.1 Basic PHP Exercises ...................................................................................... 199 7.1.2 PHP – MySQL Exercises .............................................................................. 199 7.1.3 In terms of storage ......................................................................................... 199 7.3 Design ............................................................................................................... 200 7.4 Shared Modules ................................................................................................ 201 7.5 Shared files ....................................................................................................... 201 7.6 Functions .......................................................................................................... 202