Presentation is loading. Please wait.

Presentation is loading. Please wait.

Website Development & Management More PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353.

Similar presentations


Presentation on theme: "Website Development & Management More PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353."— Presentation transcript:

1

2 Website Development & Management More PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353

3 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

4 Some Other Things (continued) Note some things in the FKAuto calculator page (calc.php) JavaScript Arrays foreach() construct Review and enhancement of email handlingemail 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 Review and revision of the script writing processprocess

5 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

6 Appendix

7 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)

8 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

9 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)

10 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

11 Revised Script Writing Process Prior to the XML/HTML Initialization Get data  From forms and other sources (but not databases)  Validate as appropriate After and before 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 and, limit PHP to scriptlets that display pre-generated HTML output blocks


Download ppt "Website Development & Management More PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353."

Similar presentations


Ads by Google