1 / 10

Website Development & Management

CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353. Website Development & Management. More PHP Odds & Ends. Instructor: John Seydel, Ph.D. Student Objectives. Upon completion of this class meeting, you should be able to: Create an onLoad event handler for a web page

yank
Download Presentation

Website Development & Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353 Website Development & Management 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 (@) • Syntax: ereg(”@”,$strTo) • Add onLoad event handler to <body> • Review and revision of the script writing process

  4. What We’ve 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 $arrTerm[0] • Index is 0 • Value is 2 • For element $arrTerm[5] • Index is 5 • Value is 7 • To add an element: $arrTerm[6] = 8; or array_push($arrTerm,8); • The number of array elements is count($arrTerm)

  7. Associative Arrays • Creating an associative array $arrCustomer[‘Person’]= “Jenny”; $arrCustomer[‘Phone’]= “867-5309”; or $arrCustomer = array(“Person”=>”Jenny”,”Phone”=>”867-5309”); • Array contents • For element $arrCustomer[’Person’] • Name is Person • Value is Jenny • For element $arrCustomer[’Phone’] • Name is Phone • Value is 867-5307 • Some typical associative arrays • Form data, e.g., $_POST[‘txtCustomer’] and other elements • Database recordset rows; e.g., $strResult[‘Model’] 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 <html . . . > and before <head> • 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 <head> and <body>, limit PHP to scriptlets that display pre-generated HTML output blocks

More Related