Matthew M.

Matthew M.

Web Application Development

Slide Duration:

Table of Contents

Section 1: Advanced PHP with MySQL
Course Introduction

13m 36s

Intro
0:00
Advanced PHP w/ MySQL
0:13
Course Introduction
0:14
Course Content
0:59
Web Application: Educator Store
1:45
Web Application: Educator Store
1:46
Object-Oriented Programming
6:09
Object-Oriented Programming Overview
6:10
MySQL
6:50
MySQL Overview
6:51
Example: Command Prompt & MySQL
8:34
What You Will Learn
9:34
What You Will Learn
9:35
Course Prerequisites
11:52
Course Prerequisites
11:53
Advanced Course Development Environment

18m 46s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Development Environment Setup
1:36
Firefox Web Browser, XAMPP, and PSPad Text Editor
1:37
Course Directory Structure
4:36
Course Directory Structure
4:37
phpDocumentor
7:23
phpDocumentor Overview
7:24
Parsing Source Code
7:44
docs Subdirectory
9:06
Asvanced PHP Course Documentation Example
10:21
Previous Educator PHP Students
14:14
Lib Directory Changes
14:38
Images Directory Changes
14:57
VERSION Constant
15:40
Comments Noting a Specific Version Number
17:04
Homework Challenge
17:30
Homework Challenge
17:31
Introduction to File I/O

35m 37s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
File I/O
1:34
File I/O Overview
1:35
Performing file I/O: 3 Steps
1:52
File Permissions
2:28
Read Permission & Write Permission
2:29
fopen()
4:47
fopen()
4:48
Two Required Parameters
5:01
Successful fopen(): File Handle and Resource
5:21
FALSE and E_WARNING Error
6:00
Example
6:39
File Paths
7:10
File Paths
7:11
File Access Modes
9:18
File Access Modes
9:19
Coding Example: fopen()
10:31
Using Relative and Absolute Path & Non-Existent File
10:32
File Pointers
15:55
File Pointers
15:56
Example File
16:11
Opening a File with fopen() Using 'r' as the Access Mode
16:22
fgets()
17:55
fgets() Overview
17:56
Coding Example: fgets() - Reading a Line at a Time
18:26
feof()
20:10
feof() Overview
20:09
Coding Example: feof()
20:50
fclose()
23:43
fclose() Overview
23:44
Coding Example: fclose()
25:02
Coding Example: Current Stock
26:10
Coding Example: Current Stock
26:11
trim ()
31:39
trim () Overview and Example
31:40
Homework Challenge
33:35
Homework Challenge
33:36
Web Application Development

36m 36s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Version 1.0 Changelog
0:31
catalog.php
0:32
Function Library: fileLIB.php
5:00
Version 1.1 Changelog
27:12
createItemDataArray() and createDeptDataArray()
27:13
outputSimpleItemLink() and outputSimpleDeptLink()
32:06
HTTP & the POST Method

34m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
HTTP Model
1:28
HTTP Model
1:29
Client-Server Model 2 Steps Process
2:00
HTTP Messages
2:23
HTTP Messages
2:24
HTTP Requests
3:09
HTTP Requests
3:10
Example: HTTP Request Header
3:17
Coding Example: HTTP Requests
4:29
HTTP Responses
7:15
HTTP Responses
7:16
Example: HTTP Response (Header & Body)
8:00
header()
11:47
header() Overview
11:48
Coding Example: header
14:02
Coding Example: header() Error
14:52
GET Method
18:55
GET Method
18:56
Coding Example: GET Method
20:13
POST Method
21:09
POST Method
21:10
Coding Example: Sample Form Using the POST Method
23:50
Accessing POST Data in PHP
26:38
Accessing POST Data in PHP
26:39
Coding Example: Accessing POST Data via $_POST
28:15
GET vs. POST
29:54
GET vs. POST
29:55
Example: Accessing POST Data via $_POST
31:20
Example: Accessing POST Data via $_POST
31:21
Homework Challenge
33:00
Homework Challenge
33:01
Web Application Development

14m 11s

Intro
0:00
Version 2.0 Changelog
0:09
Updating the Site's Current Form to Use the POST Method
0:10
Creating Admin Website
2:55
Dynamically Generated Department List
12:40
Writing to Files

17m 38s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Review of File I/O
0:40
Review of File I/O
0:41
fwrite()
1:38
fwrite()
1:39
fputs()
2:20
'r+'
2:31
Coding Example: fwrite()
2:59
fopen() Access Modes
8:41
'a' and 'a+'
8:42
'w' and 'w+'
11:34
Homework Challenge
14:47
Homework Challenge
14:48
Web Application Development

28m 14s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Updated Open File Functions
0:19
openItemsDataFile ( ), openDeptsDataFile ( ), and openLastAddedFile ( )
0:20
insertItem()
6:25
insertItem() Overview
6:26
Functions: createItemDataString ( ) and updateLastItemAdded ( )
7:07
addItemToDepartment ()
16:03
addItemToDepartment () Overview
16:04
Functions: createDeptDataString ( ) and updateDepartment ( )
17:55
HTTP POST: File Uploads

22m 51s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
POST Data Encoding
1:13
POST Data Encoding
1:14
When Data is Included in the Body of the HTTP POST Request and is of the Content Type
1:31
When Uploading Files Using HTTP POST
3:17
Uploading Files
6:22
Uploading Files
6:23
If Encoding Type is Not Set to Multipart/Formdata
9:27
$_FILES Superglobal
10:59
$_FILES Superglobal
11:00
Structure of $_FILES
12:15
Structure of $_FILES: Name, Type, tmp_name, Error, and Size
12:16
Coding Example: $_FILES Superglobal
13:34
Moving an Uploaded File
15:39
Introduction to Moving an Uploaded File
15:40
move_uploaded_file ( ): Definition and Example
16:40
Homework Challenge
21:19
Homework Challenge
21:20
Web Application Development

15m 30s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Uploading Item Image File
1:22
Uploading Item Image File
1:23
Uploading Item Image File (cont.)
2:43
Altering insertItem ( )
2:44
Helpfer Functions: getFileExtension ( ) and moveUploadedFile ( )
4:30
isValidItem ( )
13:03
Introduction to Object-Oriented Programming

32m 44s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object-Oriented Programming
0:56
Introduction to Object-Oriented Programming
0:57
Associative Arrays
5:27
Associative Arrays
5:28
Classes
7:27
Classes Overview
7:28
Defining Classes
8:24
Defining Classes
8:25
Declaring Class Properties
9:25
Coding Example: Classes
10:11
Objects
12:18
Objects Overview
12:19
Classes vs. Objects
12:49
Classes vs. Objects
12:50
Instantiating Classes
14:58
Instantiating Classes
14:59
Coding Example: Instantiate an Item Object
16:30
Object Properties
19:21
Access and Set an Object's Property
19:22
Coding Example: Set & Access the Properties of an Item Object
24:23
Homework Challenge
30:22
Homework Challenge
30:23
Web Application Development

17m 47s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 5.0 Overview
0:50
Version 5.0 Overview and Examples
0:51
Outputting Object Properties
12:38
Outputting Object Properties
12:39
Array Object Properties
14:18
Access and Set Array Value
14:19
Object Methods

39m 57s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Object Methods
0:52
Definition of Object Methods
0:53
Calling Object Methods
3:25
Calling Object Methods
3:26
Coding Example: Simple Object Methods
4:44
Object Methods and Return Values
7:02
$this Variable
10:06
$this Variable: Definition and Example
10:07
$this Variable (cont.)
15:51
$this Variable (cont.)
15:52
Getters & Setters
21:21
Getters & Setters Methods
21:22
Object Methods In Strings
25:46
Object Methods In Strings
25:47
Coding Example: Outputting Method Return Values in Strings
27:41
Using $this to Call Other Methods
28:49
Using $this to Call Other Methods
28:50
Homework Challenge
34:18
Homework Challenge: 1-3
34:19
Homework Challenge (cont.)
36:20
Homework Challenge: 4-6
36:21
Homework Challenge (cont.)
37:52
Homework Challenge: 7-10
37:53
Web Application Development

17m 30s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 6.0 Overview
0:40
Version 6.0 Changes & Examples
0:41
Item Methods
0:53
Item Class Definition: getImageFilename()
0:54
Coding Example: getImageFilename()
1:58
Department Methods
7:33
addItem(), removeItem(), and isItemInDept() Method
7:34
addItemtToDepartment() & buildDeptObject() Functions
11:46
A Default Value Needed to Be Set for $items
16:26
Object Constructors

22m 20s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object Constructors
0:32
Introduction to Object Constructors
0:33
Coding Example: Object Constructors
1:43
Defining Constructors
3:26
Defining Constructors
3:27
Coding Example: Constructors with No Arguments
4:24
Constructor Arguments
8:09
Constructor Arguments
8:10
Coding Example: Constructor Arguments
9:49
Important Notes
16:13
Important Notes
16:14
Homework Challenge
17:35
Homework Challenge: 1 - 4
17:36
Homework Challenge (cont.)
19:13
Homework Challenge: 5 - 9
19:14
Homework Challenge (cont.)
21:40
Homework Challenge: 10 and 11
21:41
Web Application Development

16m 19s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 7.0 Overview
0:39
Version 7.0 Overview
0:40
Item Constructor
2:19
Item Constructor
2:20
Department Constructor
7:47
Department Constructor
7:48
Customer Constructor
12:23
Customer Constructor
12:24
More Magic Methods

53m 37s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Magic Methods
1:12
Magic Methods
1:13
Destructors
2:45
Destructors Overview
2:46
Coding Example: Calling Destructors
4:30
Coding Example: Object Destructor
9:19
_to String ()
16:12
_to String () Overview
16:13
Coding Example: _to String () Magic Method
18:10
Access Modifiers
21:23
Introduction to Access Modifiers
21:24
Access Modifiers: Public
21:39
Access Modifiers: Private
22:18
Access Modifiers: Protected
22:41
Object Properties and Methods
23:06
Coding Example: Public Access Modifiers
26:48
Coding Example: Private Access Modifiers
28:30
_get()
31:37
_get() Overview
31:38
Coding Example: _get () Magic Method
33:30
_set ()
36:23
_set () & the Magic Method
36:24
Using Getters & Setters
44:37
Coding Example: Using Getters & Setters
44:38
Homework Challenge
50:33
Homework Challenge: 1 - 6
50:34
Homework Challenge (cont.)
51:41
Homework Challenge: 7 - 12
51:42
Web Application Development

31m 12s

Intro
0:00
Version 8.0 Review
0:12
Version 8.0 Review
0:13
private Object Properties
1:15
private Object Properties
1:16
Coding Example
2:54
_toString() Methods
6:51
_toString() Methods
6:52
Coding Example
8:09
DataFile Class
13:27
DataFile Class & I/O Operations
13:28
Using DataFile Class: Instantiate a DataFile, DataFile open () Method, and DataFile close () Method
18:09
Homework Challenge
29:35
Homework Challenge
29:36
Classes vs. Objects

37m 49s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Class vs. Object Review
0:58
Class vs. Object Review
0:59
Static Properties
2:42
Static Properties
2:43
Scope Resolution Operator (::)
5:26
Scope Resolution Operator (::) & Static Property
5:27
Coding Example: Accessing a Static Property Using the Scope Resolution Operator
7:57
Coding Example: Accessing a Static Property in a Class Definition
10:33
Coding Example: Using a Static Property as an Instance Counter
14:18
Static Methods
18:51
Static Methods Overview
18:52
Coding Example: Static Methods
21:39
Classes vs. Objects
26:28
Classes vs. Objects: Diagrams
26:29
Class Constants
30:24
Class Constants Definition
30:25
Coding Example: Using Class Constants
31:55
Homework Challenge
34:01
Homework Challenge: 1 - 5
34:02
Homework Challenge (cont.)
35:25
Homework Challenge: 6 - 10
35:26
Web Application Development

21m 7s

Intro
0:00
Version 9.0 Overview
0:12
Version 9.0 Changes & Examples
0:13
Output Class
1:08
Output Class & Static Methods
1:09
outputHtmlSelector ( ) Method
2:43
outputItemSelector ( ) Method
4:53
outputDeptSelector ( ) Method
6:42
buildObject() Methods
11:54
buildObject() Methods & Examples
11:55
Exceptions

22m 43s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
try Blocks
0:44
try Blocks Definition
0:45
catch Blocks
2:03
catch Blocks: Definition and Syntax
2:04
Coding Example: try/catch Blocks
3:48
When an Exception Object is Caught & Error Handling
5:59
Exception Class
7:02
Exception Class
7:03
Coding Example: Using try/catch to Catch an Exception Thrown from a Method
8:04
Re-Throwing Exceptions
16:39
Re-Throwing Exceptions
16:40
Coding Example: Re-throwing an Exception
17:21
Homework Challenge
20:40
Homework Challenge: 1 - 5
20:41
Homework Challenge (cont.)
22:17
Homework Challenge: 6
22:18
Web Application Development

22m

Intro
0:00
Version 10.0 Overview
0:11
Updating addItem.php, addItemToDept.php, and error.php
0:12
Updating DataFile Class: open ( ) Method & try/catch blocks
7:45
Version 10.1 Overview
13:37
Version 10.1 Changes & Examples
13:38
Updating DataFile Class: close ( ) Method & logWarning ( )
20:17
Cookies

39m 47s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is a Cookie?
1:15
Definition of Cookie
1:16
HTTP - A Stateless Protocol
2:17
HTTP - A Stateless Protocol
2:18
Purpose of Cookies
4:10
Set - Cookie Header
6:21
Introduction to Set - Cookie Header
6:22
Coding Example: Set - Cookie Header
7:38
Cookie Header
9:45
Introduction to Cookie Header
9:46
Example: Cookie Header
10:27
setcookie()
12:33
Introduction to setcookie()
12:34
Example: Using setcookie
13:54
Cookies Attributes
15:48
Cookies Attributes Overview
15:49
Common Cookies Attributes: Domain
16:24
Common Cookies Attributes: Path
17:04
Common Cookies Attributes: Expires
19:34
Coding Example: Setting Cookie Attributes
20:58
$_COOKIE Superglobal
27:03
$_COOKIE Superglobal
27:04
Coding Example: Accessing Cookies from PHP Using $_COOKIE
29:45
Security Implications
34:44
Security Implications
34:45
Homework Challenge
36:10
Homework Challenge: 1 - 4
36:11
Homework Challenge (cont.)
37:47
Homework Challenge: 5 - 7
37:48
Web Application Development

39m 11s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
instanceof Operator
1:34
instanceof Operator
1:35
Objects with Object Properties
2:53
Objects with Object Properties
2:54
Version 11.0 Overview
6:41
Version 11.0 Changes: Cart and CartItem Classes
6:42
Version 11.0 Coding Example
10:40
Version 11.1 Overview
31:03
Version 11.1 Changes & Examples
31:04
Introduction to Sessions

46m 8s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
What is a Session?
0:53
What is a Session?
0:54
Client-Side Sessions
3:51
Client-Side Sessions
3:52
Server-Side Sessions
5:04
Server-Side Sessions
5:05
Session IDs
6:26
Session IDs
6:27
The SID is Used by the Server to:
7:08
A Client Passes an SID to the Server with Each HTTP Request Via:
8:15
Sessions in PHP
12:19
Sessions in PHP
12:20
session_start()
14:40
session_start() Overview
14:41
Coding Example: Using session_start () to Continue a Session
18:03
$_SESSION Superglobal
22:06
$_SESSION Superglobal Overview
22:07
Coding Example: Setting a Session Variable via $_SESSION
25:22
Accessing Session Data
28:08
Accessing Session Data
28:09
Deleting Session Data
31:43
Deleting Session Data
31:44
Coding Example: Deleting Session Data
32:16
Configuring PHP Sessions
36:14
session.cookie_lifetime, session.cookie_domain, and session.cookie_path
36:15
Coding Example: Configuring PHP Sessions
37:28
Configuring PHP Sessions (cont.)
40:56
session.use_cookies, session.use_trans_sid, and session.use_only_cookies
40:57
Coding Example: Configuring PHP Sessions
42:25
Homework Challenge
42:55
Homework Challenge: 1 - 5
42:56
Homework Challenge (cont.)
44:10
Homework Challenge: 6 - 10
44:11
Homework Challenge (cont.)
45:27
Homework Challenge: 11 - 13
45:28
Web Application Development

11m

Intro
0:00
Version 12.0 Overview
0:12
Version 12.0 Changes Part I: Updating 'viewCart.php' & 'checkout.php'
0:13
Version 12.0 Changes Part II
5:03
Destroying Sessions

29m 59s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Destroying Sessions
1:02
Destroying Sessions
1:03
session_destroy()
2:10
session_destroy() Overview
2:11
Coding Example: Setting a Session Variable and Destroying a Session
3:18
Deleting Session Cookies
8:38
Deleting Session Cookies
8:39
Coding example: Deleting Session Cookies
9:17
Review of Steps
21:07
Review of Steps
21:08
Garbage Collection
21:50
Garbage Collection Overview
21:51
Coding Example: Garbage Collection
24:30
Homework Challenge
26:28
Homework Challenge: 1 - 4
26:29
Homework Challenge (cont.)
28:16
Homework Challenge: 5 - 9
28:17
Web Application Development

19m 14s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
_autoload()
0:46
Introduction to _autoload ()
0:47
Version 13.0 Overview
4:06
_autoload () and SessionManager Class
4:07
Updating 'viewCart.php' & 'checkout.php'
11:16
Introduction to Databases

21m 24s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Flat Files
1:09
Flat Files: Definition and Example
1:10
Problems Associated with Using Flat Files as a Database
2:15
Relational Databases
3:29
Relational Databases
3:30
Relational Database Management System (RDBMS)
3:50
Tables
7:43
Tables
7:44
Columns
9:24
Columns
9:25
What is SQL?
10:45
Introduction to Structured Query Language
10:46
Standard Data Types of SQL
12:23
Primary Keys
13:19
Primary Keys
13:20
Primary Key Examples
16:36
Primary Key Examples
16:37
Introduction to MySQL

28m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
What is MySQL?
1:33
MySQL
1:34
MySQL Monitor
5:16
MySQL Monitor Overview
5:17
XAMPP & MySQL
5:58
In the MySQL Command: hostname, username and -p
7:05
Connecting to a MySQl Server
9:52
Connecting to a MySQl Server
9:53
Using MySQl Monitor
13:48
Using MySQl Monitor
13:49
GRANT Command
15:10
GRANT SQL Command
15:11
Privileges & Objects
18:18
Username, Hostname, and Password
19:37
Specifying Objects
20:05
Creating a PHP User Account
21:41
Creating a PHP User Account Overview
21:42
Meaning of all & *.*
23:35
Example: Creating a PHP User Account
23:48
Required Homework
26:27
Required Homework: 1 - 5
26:28
Required Homework (cont.)
27:28
Required Homework: 6
27:29
Creating Databases & Tables

23m 1s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Creating a Database
1:40
Introduction to Creating a Database
1:41
Example: Creating a Database
3:33
CREATE TABLE Command
6:43
CREATE TABLE Command
6:44
Data Types
7:39
Numeric Data Types: INT, INT UNSIGNED, and DECIMAL
7:40
String Data Types: CHAR (M), VARCHAR (M), and TEXT
9:23
Colum Attributes
11:00
PRIMARY KEY Attribute
11:01
AUTO INCREMENT Attribute
11:35
Items Table
13:07
Items Table
13:08
Useful Commands
17:04
SHOW TABLES Command & DESCRIBE Utility Statement
17:05
Example: Creating an Items Table
17:58
Required Homework
20:51
Required Homework: 1 - 6
20:52
Required Homework (cont.)
21:55
Required Homework: 7 - 9
21:56
SQL Command: INSERT

27m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
INSERT Command
1:20
SQL INSERT Command
1:21
Specifying Values
3:16
Columns with Numeric Data Types
3:17
Columns with String Data Types
3:34
Columns with AUTO INCREMENT
4:07
Inserting Items
5:21
Inserting Items
5:22
Example: Inserting Items
7:03
SQL Text Files
14:04
SQL Monitor Client
14:05
MySQL Monitor & the < Operator
15:15
Example
17:35
Required Homework
22:32
Required Homework: 1 - 6
22:33
Required Homework (cont.)
24:19
Required Homework: 7 - 10
24:20
SQL Command: SELECT

24m 57s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
SELECT Command
0:42
SELECT Command: Definition and Syntax
0:43
Results of a SELECT Query
1:53
To Specify the Retrieval of All Columns from a Table
3:06
Example: SELECT Command
4:18
WHERE Clause
7:11
WHERE Clause
7:12
A SELECT Query with WHERE Clause has the Following Syntax
8:10
A Where Condition can Contain both Logical and Comparison Operators
9:44
Literal Values
13:24
Literal Values
13:25
Example: Literal Values
14:18
ORDER BY Clause
15:31
ORDER BY Clause & SELECT Query
15:32
Ascending and Descending Order
17:30
An ORDER BY Clause can Specify Multiple Columns to Order the Rows by
18:01
Example: SELECT Query with WHERE and ORDER BY Clause
20:32
Homework Challenge
21:59
Homework Challenge
22:00
Homework Challenge (cont.)
23:54
Homework Challenge
23:55
Using PHP from MySQL

32m 43s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
PHP/MySQL Architecture
0:56
PHP/MySQL Architecture
0:57
MySQLi Extension
3:05
MySQLi Extension
3:06
Steps to Using MySQL from PHP
5:53
Four Steps to Using MySQL from PHP
5:54
Step # 3
7:18
Connecting to a Database
8:12
To Connect to a MySQL Database
8:13
To Test for Connection Errors
10:20
Running an SQL Statement
11:54
Running an SQL Statement
11:55
Example
13:30
Processing the Results
15:58
For non-SELECT Queries
15:59
MySQLi Object Property: affected_rows
16:19
For INSERT Statements on Tables with an AUTO_INCREMENT Column
18:07
Closing the Connection
19:45
Closing the Connection
19:46
Coding Example
21:24
Coding Example: Using MySQL from PHP
21:25
Homework Challenge
29:00
Homework Challenge: 1 - 4
29:01
Homework Challenge (cont.)
31:10
Homework Challenge: 5 - 9
31:11
Web Application Development

30m 30s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
sprintf()
1:28
sprintf() Overview
1:29
Example
1:56
INSERT Statements with sprintf()
5:15
INSERT Statements with sprintf()
5:16
Version 14.0 Overview
10:00
Version 14.0 Changes & Examples Part 1
10:01
Version 14.0 Changes & Examples Part 2
21:58
SELECT QUERIES from PHP

24m 22s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
SELECT Queries
1:21
SELECT Queries
1:22
MySQLi_Result Class
3:17
MySQLi_Result Class: num_rows
3:18
MySQLi_Result Class: fetch_assoc ( ) and fetch_object ( )
3:59
fetch_assoc()
5:17
fetch_assoc() Overview
5:18
Coding Example: Using fetch_assoc()
9:00
stdClass Objects
12:46
stdClass Objects
12:47
fetch_object()
14:19
fetch_object() Overview
14:20
Coding Example: Using fetch_object()
16:45
Freeing Result Set Memory
18:42
Freeing Result Set Memory
18:43
Coding Example: Using free ( )
20:01
Homework Challenge
22:07
Homework Challenge: 1 - 5
22:08
Web Application Development

17m 6s

Intro
0:00
Version 15.0 Overview
0:13
Version 15.0 Changes & Examples Part 1
0:14
Version 15.0 Changes & Examples Part 2
8:43
Linking Tables

24m 32s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
A Departments Table
1:08
Departments Table
1:09
How Could We Model This in a Table: Option 1
1:26
How Could We Model This in a Table: Option 2
3:12
Database Normalization
4:37
Database Normalization
4:38
Foreign Keys
8:47
Foreign Keys
8:48
Linking Table
11:26
Linking Table
11:27
Multiple Column Primary Keys
15:30
Multiple Column Primary Keys
15:31
Example
18:51
Required Homework
22:34
Required Homework: 1 - 3
22:35
Required Homework (cont.)
24:10
Required Homework: 4
24:11
Web Application Development

24m

Intro
0:00
Version 16.0 Overview
0:11
Version 16.0 Changes
0:12
Version 16.0 Coding Examples
4:12
Version 16.0 (cont.)
18:30
Version 16.0 Changes & Examples Part 2
18:31
SQL Command: DELETE

10m 33s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
DELETE Statement
0:30
DELETE Statement & Its WHERE Clause
0:31
Delete All Rows From a Table
2:57
Using DELETE from PHP
4:04
Using DELETE from PHP Overview
4:05
Coding Example: Using DELETE from PHP
6:37
Homework Challenge
8:53
Homework Challenge: 1 - 4
8:54
Web Application Development

16m 2s

Intro
0:00
Version 17.0 Overview
0:11
Version 17.0 Changes
0:12
Version 17.0 Coding Example
2:51
Transactions
12:50
Database Transaction
12:51
Steps in Using Transactions
14:00
SQL Command: UPDATE

32m 14s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
UPDATE Statement
0:54
UPDATE Statement & Its WHERE Clause
0:55
Example: UPDATE Statement
3:32
Using UPDATE from PHP
5:21
Using UPDATE from PHP Overview
5:22
Coding Example: Using UPDATE from PHP
6:53
htmlspecialchars()
9:04
htmlspecialchars()
9:05
Encoding Special Characters
9:23
Coding Example: htmlspecialchars()
13:41
addslashes()
20:40
addslashes()
20:41
Coding Example: addslashes()
22:52
Homework Challenge
27:55
Homework Challenge: 1 - 2
27:56
Homework Challenge (cont.)
30:14
Homework Challenge: 3 - 5
30:15
Homework Challenge (cont.)
30:41
Homework Challenge: 6 - 9
30:42
Web Application Development

12m 33s

Intro
0:00
Version 18.0 Overview
0:12
Version 18.0 Changes
0:13
Version 18.0 Coding Example
1:24
SQL: Joins

42m 16s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
DATETIME Data Type
1:52
DATETIME Data Type
1:53
Modeling Orders
5:12
Modeling Orders
5:13
Customers Table
10:46
Customers Table
10:47
Example
16:18
Example: Order Table in MySQL
16:19
Joins
22:26
Joins Overview
22:27
Inner Join
23:09
Example: Joins
24:11
Join Conditions
28:14
Join Conditions
28:15
Example
28:32
Join Queries
30:00
Example: Join Conditions in MySQL
30:36
Implicit Joins
34:42
Implicit Joins
34:43
Example: Implicit Joins
35:57
Aliases
37:28
Introduction to Aliases
37:29
Example: Aliases
38:55
Required Homework
40:32
Problem 1
40:33
Problem 2
41:01
Problem 3
41:17
Web Application Development

29m 34s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Inserting Orders
0:44
Inserting Orders
0:45
Version 19.0 Overview
3:45
Version 19.0 Changes & Example Part 1
3:46
Version 19.0 Changes & Example Part 2
13:18
Version 19.1 Overview
21:10
Version 19.1 Changes
21:11
Version 19.1 Coding Example
22:18
User Authentication

26m 13s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
User Authentication
1:31
User Authentication
1:32
Authentication with Sessions
2:34
Authentication with Sessions
2:35
Four Steps in Authentication via Sessions
2:50
Using Sessions to Restrict Access
3:58
Using Sessions to Restrict Access
3:59
Coding Example: Restricted Access Area
4:47
Authentication Methods
5:54
Authentication Methods Overview
5:55
Coding Example: Authentication Methods
7:31
Logging Out
9:57
Logging Out
9:58
Coding Example: Log Out
10:47
Users Table
13:50
Users Table
13:51
Example: Creating a Users Table
15:08
Password Hashing
17:30
Password Hashing
17:31
PHP and MySQL Built-in Hash Functions: sha1 ( ) and md5 ( )
18:43
Coding Example: Password Hashing
19:27
Required Homework
24:41
Required Homework: 1 - 4
24:42
Web Application Development

14m 36s

Intro
0:00
Version 20.0 Overview
0:13
Version 20.0 Changes & Examples Part 1
0:14
Version 20.0 Changes & Examples Part 2
5:05
Version 20.0 Changes & Examples Part 3
7:29
Version 20.0 (cont.)
8:31
Version 20.0 Changes & Examples Part 4
8:32
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Advanced PHP
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
Since this lesson is not free, only the preview will appear on your website.
  • Discussion

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Lecture Comments (2)

0 answers

Post by Chunliang Yao on May 22, 2016

where can i download the codes please?

0 answers

Post by sorin dragon on March 16, 2016

I can't get the images on web app. When I look to the source this is the link:

http://localhost/educator-php-advance/web_app/version-0.0/educator-php-advance/web_app/version-0.0/images/1006.jpg

I didn't change anything in config file but I think somewhere in this file it is a mistake.

Web Application Development

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:16
    • Lesson Overview
  • Version 1.0 Changelog 0:31
    • catalog.php
    • Function Library: fileLIB.php
  • Version 1.1 Changelog 27:12
    • createItemDataArray() and createDeptDataArray()
    • outputSimpleItemLink() and outputSimpleDeptLink()

Transcription: Web Application Development

Hello again, and welcome back to Educator.com's Advanced PHP with MySQL course.0000

Today's lesson is going to be our first lesson where we add functionality to our Educator Store web application.0005

And in particular, today we are going to be incorporating what we learned in our last lesson on reading data from files.0010

We are going to incorporate two new versions of our web application in this lesson: a version 1.0 and a version 1.1.0018

And it is going to make use of what we learned about reading from files in the last lesson.0027

What we have had so far in our baseline version of our web application is: we have had all of the information stored,0035

about the departments and the items in our store, in this file: catalog.php.0041

For example, if we look at catalog.php from version 0.0 (our baseline version), you can see that information about each item0046

is contained in this array called itemCatalog, where we have the name, the price, the description, the file extension, and so forth.0058

And then, additionally, we have an array called departments that contains information about each department--0067

containing the department's name and all of the items in that particular department.0072

In this case, they are specified by item ID.0078

Now, what we do is include this file in all of our scripts; and so, let's say (for example) we had a larger store with 1,000 items in it:0082

that means we would be including this file with 1,000 items into every page that we load.0091

And that could consume a lot of memory and really slow down our application, and it is not very efficient.0096

Additionally, every time we want to add an item to our store, we have to go and update this PHP code (in this case, catalog.php),0103

which would typically require a web developer to do.0110

What we can do instead is move this information into text files, or data files, which we learned how to read in the last lesson.0114

And what that is going to do is: that means that, every time a page is loaded, we are not going to load catalog.php anymore.0121

We are only going to read information about an item or a department as it's needed, through a function library0127

that we are going to create, that is going to read from these new data files that we are creating.0133

And additionally, you could even manually edit these data files, so we could add new items to the store easily.0139

And also, as the course progresses, we are going to add an administrative interface that is going to allow us0146

to add items to the store by using a web interface to add items to these data files.0151

And what that means is that now, instead of updating an actual PHP code file to the web server, we can use a web interface0161

to update our text file, or manually edit it by hand; and we don't need to be a PHP developer to do that.0169

What we have done is taken the information out of this catalog.php file and included it into two different data files.0178

The first one is called items.txt, and it is a file where each line of the file represents an item in the store and the item's data.0187

And it is a delimited list, and it is delimited using the vertical bar, sometimes known as the pipe, which is typically on the backslash key on your keyboard.0201

We use that to delimit the different fields.0211

What we have, for example, is: the first field that we have for each item is its ID.0214

Then we have a vertical bar and the name of the item; then we have the cost of the item and the description of the item.0219

And then finally, after this last vertical bar, we have the image extension.0228

What we have done is taken this information--for example, for item 1001--that was in this itemCatalog array,0233

and condensed it down into this text file, items.txt.0241

And we have done that for each of the different items in the store--1001 through 1006.0245

Additionally, we have also created a file called departments.txt.0250

What that does is mimics this departments array that we have created,0254

that lists the different departments, with their names and the different items contained in the department.0259

The way this file is set up is: each line represents a department in the store, and the data fields of that department are delimited by the vertical bar.0265

And here, we have that the first data field is the department ID; then we have the name of the department;0278

and then, the third field is another delimited list (in this case, it's a comma-delimited string).0285

And what it is: it is a comma-delimited string of all the item ID's of the items in a particular department.0291

And so, what we have done is: again, we have moved this from a PHP script into a flat text file that we can store on our web server,0301

that we can edit manually if we need to; and then, what we are going to do is develop functions0309

that enable us to access information about items and departments from these text files.0314

We are going to, in this version, create a new library called fileLIB.php0319

that contains the functions for retrieving information about the store's items and information about the departments from these data files.0326

If we go and look, in our original version, this is the PHP Documentor documentation generated for our web application.0334

This is for version 0.0, our baseline version.0343

And as you can see here, we have three categories of functions: config, output, and utility.0349

Well, in our new version, we have a file category as well; and it contains functions that were created in this file called fileLIB.php.0354

And what fileLIB.php is: it has a number of different functions (let's blow this up some) for getting information,0365

about items and departments, that is contained in those data files.0374

For example, we have the getDepartment function; and what that function does is retrieves information0377

about a department from the store database (in this case, the departments.txt data file).0382

We have the getDepartments function, which retrieves information for all of the departments in our store.0389

It loads all of the information in that departments.txt file.0395

We have the getItem function, which retrieves information about an item from that items.txt file.0399

And then, we have the getItems function, as well, which retrieves an array of all of the items in the store.0405

It contains information about all of the items in the store.0412

And so now, in our scripts, when we want to access information about an item, rather than...for example, if we look at item.php...0414

rather than, in our code (for example), explicitly referring to itemCatalog, which was included in config.php,0426

to get information about an item, it is going to be turned into a call to this new getItem function, where we pass it the item ID.0432

All of those itemCatalog references are going to be removed; all of the references to this departments array are going to be removed,0443

because in our new web application, we are not going to be including this config.php file,0450

because all of that information is now in these text data files.0455

What we can do is look at the getItem function (let's see if I can blow this up a little bit).0464

And if we look at the documentation for it, getItem says that it retrieves information about items from the store database.0476

And what it does is: it takes an item ID, and it goes through and opens up that items.txt file.0488

It searches for a line that begins with the item ID that it is looking for; and then, if it finds that,0495

it goes ahead and creates an associative array containing all of the information about that particular item.0500

So, the code for this example: the first thing it does is tests to make sure that it is passed a numeric value for an item ID; if not, it returns false.0508

And then, what it does is (in this first if statement) calls a function called openItemsDataFile,0518

which is a function we have created in our function library that is used to open a connection to that items.txt file.0523

And if this is successful, this is going to return true; it is going to loop over the different lines in that file, searching for the particular item ID.0532

We just have a quick look at openItemsDataFile.0542

This is a function, and all it does is calls fopen on our items file (which, by the way, is something that we defined as a constant in our config.php file).0545

For example, if we click on itemsDataFile, this links to the documentation for config.php.0560

And you can see, what we have done is defined a couple of new constants here: one called itemsDataFile,0573

which states that the items data file is called items.txt, and it is in the include directory.0580

We defined what is known as the items data separator--we are telling PHP that the different data fields in that file are separated by the vertical bar.0589

And then, we are also defining the departments data file, which says the information0602

about all the departments is stored in departments.txt in our include directory.0607

And then, we also define two other data separators: one that says the data fields in the department line in departments.txt0612

are separated by vertical bars, and then another constant that says that the items in a particular department are separated by commas.0624

So, if we go back and look at departments.txt, we can see that this vertical bar character is our department data separator.0634

And then, this comma here is what we call the department's item ID separator.0646

And that is basically saying that we are separating the ID's in this third field by a comma.0652

And we are going to use these constants in our different functions in fileLIB.php.0656

In this openItemsDataFile, we open our file; we use the fopen command.0666

We open it for reading, which is going to put the file pointer at the beginning of the file.0671

We are going to use our error suppression operator, as we learned about in the last lesson, to suppress any error, if there is an error opening the file.0677

If there is a problem, we output an error message; if there isn't a problem, we return a handle to that open file.0684

Back in getItem, the second thing we do is call this openItemsDataFile, so we get a file handle to that data file.0692

And then, what we do is use a similar scenario to what we went over in the last lecture, which is:0701

we loop over the contents of this file, reading one line at a time from the file.0709

We make use of this feof character to find out when we are at the end of the file.0716

And what we do is: we read a line from the file, using fgets; and we trim any white space off of it.0721

And then, using this ITEMS_DATA_SEPARATOR character, which we click on (we saw it as the vertical bar), what we are going to do is:0728

we are going to explode or take each line that is in items.txt, and place it into an array,0735

and separate the contents based on where the vertical bars are.0742

So, we are going to have an array that is going to contain the item ID, the name, the price, the description, and the file extension.0746

The next thing we do is: in our items.txt file, the first data field for a particular item on a line is the item ID.0755

When we read this line using fgets, and we run the explode function on it, the first element in the array0766

that that explode function is going to generate is going to be the item ID.0774

So, what we do is: we then test if that first element (which would have index 0) is equal to the item ID passed into the function.0777

We are saying, "Is the item ID of the current line that we are on equal to the item we are looking for?"0789

If it is not, then we are just going to say, "Continue this while loop, looping to the next line."0797

Then, if this condition turns out to be false (meaning that it is the item ID that we are looking for),0802

then what we are going to do is call this function createItemDataArray.0812

And what that function does is: it builds an associative array of all the information in that line of items.txt.0818

If we click on the link to createItemsDataArray, we can see, it creates an associative array0828

containing all of the information about an item taken from the data fields in a line in the item's data file.0833

And it explains that the associative array that it returns contains the following keys: name, price, description, and image file extension.0839

And those keys correspond to the different values in items.txt: the name, the price,0847

the description, and then (all the way down at the end) the image file name.0855

So, we are essentially creating an array that mimics what we used to create in our itemCatalog array.0859

For item 1001, we created an associative array with the key's name, price, description, and image file extension.0866

We are creating that same array, but we are doing it in this new function library.0872

All this item array does is tests to see that there are at least five elements in this array that it was passed,0879

to make sure that it has the five elements needed for an item: its ID, its name, its price, its description, and its image file extension.0886

If it is not equal to 5 in length, it returns false; if it is equal to 5, it goes ahead and creates this item array and associative array,0895

and adds the name, price, description, and image file extension to it, and returns that associative array back to the calling function--0904

which, in this case, was our getItem function.0912

So, getItem opened the data file; it looped over each line of the file, looking for an item that had the item ID we were searching for.0916

If it found one, it created an item data array, an associative array that has the name, price, description, and file extension keys in it.0925

And as long as that function createItemDataArray doesn't return false, what we are going to do is:0937

we are going to break out of the loop, because we found the item that we were looking for.0942

We have loaded that item's information from the file, and so we have gotten the information we needed.0945

Then, we are going to complete this loop of opening, reading, and closing a file by calling the fclose method.0952

which is, when we pass it the file handle that we generated up here in openItemsDataFile,0959

going to output an error message if there is an error closing the file.0967

And then, if this item array is not empty (meaning that we were able to find the item in our items.txt0972

and load it with that item's information), we return that item array; and if not, we return false.0982

There is also a message on here that says that if we had an error opening the item's data file, we return false, as well.0987

This getItem method allows us to search through that items.txt file, look for a particular item, and pull out the information that we need.0993

For example, in our item.php file, one of the things we do at the beginning of this file is...1003

Well, first of all, if you remember (and if you look at the original 0.0 version of the web app), this item.php file takes one GET parameter.1014

And it is an item ID that specifies the item ID we want to load the information for.1026

And so, what we do here is: now, when we load up the information about the item, we call this new getItem method1033

that is provided in this function library, and pass it the current item ID--1040

whereas, in our old version, the way we loaded the item was by using that itemCatalog array1043

defined in catalog.php, and passing it the key, which was the item's ID.1051

For example, we look up itemCatalog, 1001; we pass it the key 1001, and then that would return this array here.1056

Now, we are replacing that array lookup with this new function call that is going to load the item's information from the file.1064

And what we have done is: we have done the same thing for the departments.1073

We have created a method called getDepartment that is going to load departments' information from the file.1081

It works very similarly to the getItem function: it opens the departments data file; it loops over each line of the file,1086

looking for the department ID of a particular department we are trying to look up.1097

If it finds it, it creates an array of that department's information; then it closes the file,1103

and returns the array containing the department's information, or false if it couldn't be found.1108

The one difference here is that, if we look at createDeptDataArray,1114

what we can see is that this returns an associative array containing a key name and a key items.1117

Name is going to have a value that is a string, which is the name of the department.1123

Items is going to be an indexed array of all the item ID's of all the items in that department.1128

So, if we look at departments.txt, we can see that (for example) for department 1, it has the name Apparel.1132

And then, it has two items in it: 1001 and 1004.1139

In this createDeptDataArray, what we do is: we extract, from the array that contains all of the information on the line in the file, the name of the department.1144

And then, what we do is, on the third element in that array (which is the comma-separated list1160

of all the items' ID's), explode on that string, using the department's ID separator, which is a comma,1166

that says, "Give me an array containing all the item ID's of the items in the department."1174

And then, what we do is loop over that array and create an indexed array containing all of the item ID's of the items in the department.1179

And then, we add that array to the department associative array with the key items.1191

So, getDepartment makes use of this function to generate its department information.1198

And it works the same way as the getItem does, except it's operating on the departments.txt file, versus the items.txt file.1203

And as mentioned, we also have a getDepartments function, which is used to go through and read every line1213

of the departments.txt file, and create a giant associative array with the key that is the ID of the department,1224

and then an array that contains all of the department's information.1235

For example, formerly, in catalog.php, this departments array--this is basically what we are going to get when we call this getDepartments function now.1238

This array has been replaced by this getDepartments function.1250

It is going to create an associative array with keys that are the ID's of a particular department.1253

And then, the values associated with those keys are going to be another array that contains1259

information about the department, such as its name and the items in that department.1264

That is the getDepartments function; we have the same thing for the getItems function, which loads an associative array1270

of all the items in the store database, which we use in our viewCart.php script.1278

And what that does is mimics the creation of this itemCatalog array.1285

It has a key that is the particular item's ID, and then, associated with each of those keys is an array containing information about a particular item.1289

And, as mentioned, we use that in viewCart.php, because in viewCart.php, we load all of the items in the store,1299

and then output a table listing links to each of those items.1305

One thing to note, to show the use of these in actual code, is if we look at header.phtml.1310

Well, in header.phtml, that is what outputs our left-hand navigation bar.1317

The way it does that is by looping over all of the departments in the store, outputting links to those department pages.1320

Well, in our last version of the web application, we directly accessed this departments array in catalog.php1325

in order to load information about a particular department, to output a link to it.1335

Now, if we look at the new version of it, what we have done is replaced that with a call to this getDepartments function.1339

So, we are no longer accessing that statically-defined array in catalog.php.1347

We are calling this getDepartments method, which is going to be able to read from that data file1351

and pull up information about all the different departments that we have in the file.1356

One thing to note, also, is that, in item.php (for example)--this is one example of where1364

we have used the getItem method to pull information about an item for display.1372

So, for item.php, we want to load the information for a particular item, so we call this getItem function--1378

whereas, in the previous version of item.php, we loaded it from that static array, itemCatalog.1383

I'm not going to go over all of the different examples; there are many different spots where these new functions are used1391

throughout this version of the web app, and you can see them on the change log.1397

But these are just a couple examples of how these functions that we have created are used throughout the code.1400

One other thing to mention is: we have also created two functions called deptExists and itemExists.1408

And those functions are used to read that data file--for example, with itemExists, you pass it an item ID,1415

asking, "Does this item exist in the store database?"--so you pass it the item ID 1001.1422

The itemExists function will go ahead and open up items.txt and search through it, looking for an item with that particular item ID.1427

If it is found, it returns true; if not, it returns false.1435

deptExists functions in the same way, except it looks through departments.txt for a particular department.1437

One of the nice things that we can notice about this is: if we go to version 1.0, this new version of the web application,1446

and we load store.php and go to viewCart (I'll reduce the size a little bit), you can see here1462

that it lists all of the different items in the store, because what happens is: it is calling this getItems function1469

that we have created, and loads all of the information about those items, and then outputs a table of them.1474

Well, because now we are reading from a file, instead of having to go back and updating catalog.php,1480

adding a new entry to this itemCatalog array that says "this is item 1007; this is its information,"1487

we can simply go and update items.txt, and just add a new line to it, and create item 1007.1495

I'll say it's a baseball, $9.99, "Use this to throw..." and we'll say its image extension has extension .jpg.1504

We save that; now, when we go and reload our shopping cart, we can see that the new item has been added to the store.1519

It did it dynamically: it was able to go out and read from that file and add information about that new file.1527

We have added a new item to the store by simply editing that text file, rather than going in and messing with PHP code1533

and creating a new entry in the itemCatalog array, which would get loaded on each page,1539

which would increase the memory needed to load a particular page, which would slow things down.1545

Now, one thing you will notice here is that the image doesn't show up.1550

That is just because I haven't created an image for this item "Baseball."1551

But also, what we would do is (as you will see when we develop our admin website) create a facility to upload an image for a new item,1555

so that, when we create a new row in this items.txt file, we will also upload an image that gets associated with it.1562

But, as you can see, we have simply added the item by adding a row to that file.1571

Similarly, we could go to departments.txt and create a new department.1578

Let's create a department called All; and we are going to include all of the items in the store in that department, including the new one.1584

Now, if we save that and go to our home page, we can see that there is a new department here, added, that is All.1602

When we click on All, we can see, it lists all of the items in the store.1610

So, you can see how now, by simply changing this text file, we can add and delete and alter items within our store,1614

and also add and delete departments with relative ease: we are just editing a text file.1623

In the next version of the web application, we are making some slight alterations to createItemDataArray and createDeptDataArray.1634

Those two functions are what we use to build up an associative array of information about an item and about a department.1643

If we look back at the documentation for (for example) createDeptDataArray, in the documentation of the function,1652

we can see that it returns the department's information in an associative array with the keys name and items,1664

where name is the name of the department, and items is an indexed array of all the items' ID's in the array.1670

If we look at createItemDataArray, it returns an associative array with these four keys in it.1675

Well, now what we are going to do is: because an item is its own object, and a department is its own object,1680

and the ID of that item is part of that object, we are going to have these functions1687

return an array that contains that item ID or that department ID itself.1692

If we look at the new version of our documentation, and we look at createItemDataArray (for example),1697

we can see that now, it actually returns an associative array that also contains the item ID.1703

And what we have done is just added a line to this file that adds the item ID,1709

which is at the 0-index position of the array that we create from the particular line in the items.txt file,1715

and just created a key called itemID and set that value equal to it.1723

Similarly, for createDeptDataArray, you have added a key to the array we're returning called deptID.1727

And you can see here that, to the department array we are returning, we add the key deptID with the department's ID.1732

So now, because these functions are used by getDepartment, getDepartments, getItem, and getItems,1739

any time we call these different functions to get information about an item or department,1746

the associative array it is going to return is also going to have information that contains that item's ID.1750

For example, one of the things that that is going to do is: if we look at outputItemLink,1757

in our previous version of outputItemLink, which is one of our output functions1763

that outputs an image and text link to an item's page, we can see that it took two parameters.1767

One was the ID of the item, and one was an associative array containing the item's name, image file extension, description, price, and so forth.1773

Well, because now when we load an item from this items.txt file, we are creating an array that already has that item's ID in it,1782

we don't need to have this parameter anymore; we can just pass it an associative array that contains all of the item's information.1791

So, in the new version of outputItemLink in this new version of the web application,1798

we can see that it only takes one parameter, and it takes parameter item.1804

And what it does is: it will pull the item ID out of that associative array.1808

And because all of our item associative arrays are going to be generated by (for example) the getItem function1813

that reads from our data file, they are going to contain the item ID.1819

And so, that puts all that information in one, so now we have eliminated two parameters and put them into one.1825

What we have done is updated all of the functions like outputItemLink and all of the source pages1833

to make use of the fact that these associative arrays returned1840

by getItem and getDepartment already contain the item and department ID's.1844

For example, if we look at item.php from the last version, version 1.0, we can see that, in the section where we output1849

information about the item, when we output the item's ID, we reference this currItemID variable,1861

which is the GET variable for that script that has the item ID.1867

And then, when we output the price and the item's name, we use this currItem array,1870

which is an associative array, generated in the beginning here by getItem.1876

But because that item ID is now contained in this array generated by getItem, we are going to access it using that array.1882

So, in the new version of item.php, you can see that this line that was formerly currItemID1888

is now going to access the item ID from the item associative array that we get back from the getItem function.1898

And we have done that, and in all of the different parts of our web application where we have needed1908

to get an ID--a department ID or an item ID--we now access the item or department array directly,1913

rather than using these other external variables, such as currItemID.1921

Now, finally, the other thing that we have done is created two new functions called outputSimpleItemLink and outputSimpleDeptLink.1927

And we have added these to our outputLIB, or output library.1935

These are just created to clean up some of our code, because we have found a lot of places in the code1939

that were actually creating simple links to an item's page or a department's page.1944

For example, on the home page of our application, we have links to all the different departments, and links to all the different items.1948

And if we look at store.php, we can see that, in this new 1.0 version: now, when we load a department's information,1963

we use the getDepartment function, rather than accessing that department's array in catalog.php.1974

But then, we call this output function that says, "Create a link to departments.php; set the ID equal to 1; and also set the body of that link equal to name."1979

So, what we have done now is created a function that is going to output a simple link to a department,1990

which is just...the body of the link is just going to be the department's name, and then the link is going to be to the department's page.1995

If you look here, we have similar code here for outputting (for example) department 2.2001

This code (let me copy and paste it up here, next to the output link code for department 1) is almost exactly the same, except for this 2 here.2010

So, any time we see something that we can reuse, we want to take advantage of that.2020

Now that we have this department object that contains its ID and its name, we can create a function2025

where we can simply pass it a department (we could call getDepartment, for example).2029

And this new function will then be able to extract all of that information from the array of information returned by getDepartment.2041

If we go and look at our new store.php, we can see that now, when we output a department,2049

we have (let me clean this back up)...for example, to output the link to department 1, all of this code2054

now simply becomes this code here--one line--and it's a call to this new function, outputSimpleDeptLink,2066

which takes an associative array that contains all of the information about an item, including its department ID and its name.2073

We generate that array by calling the getDepartment function, which we created in our last version, 1.0, of the web app.2079

We say, "Get the associative array for department 1."2086

So, we are going to go look up department 1 in our file departments.txt, and we are going to say, "Output a link to that."2089

And if we go and look at the code (for example) for outputSimpleDeptLink, we can see:2096

it simply calls that same outputLink message that we had directly called in store.php before.2103

But now, we can make a simple function call, where we just pass it a department associative array.2110

And it will go ahead and create this link for us.2117

So now, instead of having to load the department, extract the department ID, extract the department name,2119

and call this outputLink function, we can make it cleaner by making one simple function call.2125

We have also done the same thing with this function outputSimpleItemLink, which does the same thing for an item.2129

You pass it an item associative array; it extracts the item's ID, extracts the item's name, and creates a simple link for it.2135

So, on our store page, you can see that we have also--to output, for example, the links to the item pages--2141

called outputSimpleItemLink for item 1001; we make a call to outputSimpleItemLink, and then we pass it2149

the associative array that contains information about item 1001.2156

And we get that information by calling our new function getItem, which is going to load the information about item 1001 from the items.txt text file.2160

And what these functions do is make use of the fact that our associative arrays created by createItemDataArray and createDeptDataArray2173

now have the departments' ID information, and items' ID information, as well.2184

That ends today's lesson; thank you for watching Educator.com--I look forward to seeing you next time.2192

Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.