Website Development - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Website Development

Description:

Use the foreach() construct to loop through an array of data ... Use switch() in place of the if()/elseif() construct ... foreach() construct. Review and ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 11
Provided by: Econ82
Category:

less

Transcript and Presenter's Notes

Title: Website Development


1
Website Development Management
CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/m
is3353
  • More PHP Odds Ends

Instructor John Seydel, Ph.D.
2
Student Objectives
  • Upon completion of this class meeting, you
    should be able to
  • Create an onLoad event handler for a web page
  • Use the foreach() construct to loop through an
    array of data
  • Use ereg() to validate email addresses
  • Use switch() in place of the if()/elseif()
    construct
  • Discuss how data are stored and processed using
    arrays

3
Some Other Things (continued)
  • Note some things in the FKAuto calculator page
    (calc.php)
  • JavaScript
  • Arrays
  • foreach() construct
  • Review and enhancement of email handling
  • Replace if() construct with switch() construct
  • Check for a valid email address
  • Use ereg()
  • Case-sensitive use eregi() for case-insensitive
  • Alternative to preg_match(), which is a
    Perl-compatible function
  • Search for an at symbol (_at_)
  • Syntax ereg(_at_,strTo)
  • Add onLoad event handler to ltbodygt
  • Review and revision of the script writing process

4
What Weve Looked at Today
  • Using JavaScript to create an onLoad event
    handler
  • How for() and foreach() constructs work
  • The ereg() function
  • Comparison of switch() and if()/elseif()
  • Array concepts

5
Appendix
6
Arrays
  • Creating a simple array
  • arrTerm array(2,3,4,5,6,7)
  • or
  • arrTerm range(2,7)
  • This is an indexed array
  • For element arrTerm0
  • Index is 0
  • Value is 2
  • For element arrTerm5
  • Index is 5
  • Value is 7
  • To add an element
  • arrTerm6 8
  • or
  • array_push(arrTerm,8)
  • The number of array elements is count(arrTerm)

7
Associative Arrays
  • Creating an associative array
  • arrCustomerPerson Jenny
  • arrCustomerPhone 867-5309
  • or
  • arrCustomer array(PersongtJenny,Phonegt8
    67-5309)
  • Array contents
  • For element arrCustomerPerson
  • Name is Person
  • Value is Jenny
  • For element arrCustomerPhone
  • Name is Phone
  • Value is 867-5307
  • Some typical associative arrays
  • Form data, e.g., _POSTtxtCustomer and other
    elements
  • Database recordset rows e.g., strResultModel
    and other

8
Review Sending eMail
  • Makes use of the mail() function
  • String Arguments accepted
  • Recipient
  • Subject
  • Message
  • Header
  • From (overrides value specified in php.ini)
  • Reply-to
  • Other . . .
  • Consider a one-line example (poor coding)

9
Process Guidelines for Writing Scripts Original
Recommendation
  • Start by initializing
  • Assign initial values to variables
  • Define constants if any
  • Get data
  • From form
  • From other sources
  • Prepare data for processing
  • Write the processing logic
  • Branching as appropriate
  • Calculations as appropriate
  • String manipulations as appropriate
  • Other processing (e.g., send mail, write to
    database, . . . )
  • Format results for output as appropriate

10
Revised Script Writing Process
  • Prior to the XML/HTML
  • Initialization
  • Get data
  • From forms and other sources (but not databases)
  • Validate as appropriate
  • After lthtml . . . gt and before ltheadgt
  • Prepare data for processing
  • Get data from database
  • Write the processing logic
  • Branching, calculations, and string manipulations
    as appropriate
  • Other processing (e.g., send mail, write to
    database, . . . )
  • Other database queries
  • Format results for output as appropriate
  • Within ltheadgt and ltbodygt, limit PHP to scriptlets
    that display pre-generated HTML output blocks
Write a Comment
User Comments (0)
About PowerShow.com