SlideShare une entreprise Scribd logo
1  sur  40
Introduction to Web Programming with PHP Scripting Language for Applications in Agricultural Climatology  Title
Course Outline ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Background ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Source: International Telecommunication Union (ITU) http://www.itu.int/ITU-D/ict/statistics/maps.html
About PHP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Server Client javascript browser php web-host
Server & File Transfer ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Basic syntax & first exercise ,[object Object],[object Object],[object Object],[object Object],<?php ?> <html> <head>  <title>PHP Test</title> </head> <body> <?php  echo &quot;<p>Hello World</p>&quot;;  ?>  </body> </html> http://www.php.net/manual
Input (basic) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.php.net/manual
Input (syntax) Syntax (example): View this example <html> <head>  <title>PHP Test</title> </head> <body> <?php if (isset($_POST['submit'])) { echo &quot;Hi, &quot; . $_POST['name']. &quot;! <br/>&quot;; } ?> <form action=&quot;formexample.php&quot; method =&quot;post&quot;> <p> Name: <br/> <input type = &quot;text&quot; name=&quot;name&quot; size =&quot;20&quot; maxlength =&quot;40&quot; value=&quot;&quot; /> </p> <input type=&quot;submit&quot; name = &quot;submit&quot; value&quot;Go!&quot; /> </form>  </body> </html> http://www.php.net/manual
Comments & Output ,[object Object],[object Object],[object Object],[object Object],[object Object],Single line // comment Multi line /* comment comment */ <?php print (&quot;test print&quot;); print &quot;test print&quot;; ?> http://www.php.net/manual
Output (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.php.net/manual
Data types Boolean (true or false) $variable = false;  // $variable is false $variable = 0;  // $variable is false $variable = true;  // $variable is true $variable = 1;  // $variable is true $variable = 5;  // $variable is true Any non-zero value – true Integer Whole number, no fractional parts Maximum supported integer size is typicalla 2^31 Float Floating-point number -- contains fractional parts. String Sequence of character treated as a contiguous group http://www.php.net/manual
Data types (cont'd) Array Series of similar items. Index collection of data values. Each index (key) references to a corresponding value. Example: member[0] = &quot;John&quot;; member[1] = &quot;Marry&quot;; member[2] = &quot;Suzzie&quot;; http://www.php.net/manual
Data types (cont'd) Object Must be explicitly declared: Class -- attribute, function Class definition serves as template and cannot itself be manipulated. Instead, objects are created based on this template -- use 'new' keyword. soybean object is created and can then it attribute can be set by making us of the method setGroup() Class plant { private $group; function setGroup($status){ $this->group = $status;  } } $soybean = new plant; $soybean->setGroup(&quot;dicots&quot;); http://www.php.net/manual
Type casting Converting one type to the other example: $variable1 = 13; $variable2 = (double) $variable1; // 13.0  $variable1 = 4.2; $variable2 = (int) $variable1; // 4 (truncated, not round) http://www.php.net/manual
Variables Scope Local Variables A variable declared in a function is considered local. It can only be referenced in that function. When you exit the function in which a local variable has been declared, that variable and its corresponding value are destroyed. View this example $x = 2; function assignx() { $x = 0; echo &quot;x inside function is $x <br>&quot;; } assignx(); echo &quot;x outside function is $x <br>&quot;; http://www.php.net/manual
Variables Scope (cont'd) Global Variables Global variables can be accessed in any part of the program To modify global variabl, it must be explicitly declared to be a global in the function in which itis to be modified. View this example $x = 2; function assignx() { Global $x; $x = 0; echo &quot;x inside function is $x <br>&quot;; } assignx(); echo &quot;x outside function is $x <br>&quot;; http://www.php.net/manual
Variables Scope (cont'd) Static Variables Static variable does not lose its value when the function exists. View example without static View example with static function keep_track() { Static $count = 0; $count++; echo &quot;$count <br>&quot;; } keep_track(); keep_track(); keep_track(); http://www.php.net/manual
Variables Scope (cont'd) Superglobal Variables Predefined variables View example HTTP_USER_AGENT provide user's browser information For more examples of similar superglobal variables, go to: http://us3.php.net/manual/en/reserved.variables.server.php   echo &quot;Your browser is: $_SERVER['HTTP_USER_AGENT']&quot;; http://www.php.net/manual
Operators For list of operators in php, go to: http://us3.php.net/manual/en/language.operators.php The list includes: arithmetic operators (*, /, +, -) string operator, ie concatenate with &quot;.&quot; logical operators (&&, ||) equality operators (==, !=) http://www.php.net/manual
Control flow Conditional Controlling the flow of execution depending on the specified condition defined by expression Exercise 1: if statement – thermal time calculation Exercise file View output if (expression) { statement; } if (expression) { statement; } else  { statement; } if (expression) { statement; } else if (expression) { statement; } else { statement; } http://www.php.net/manual
Control flow (cont'd) Conditional Use as variant of if-else combination when need to compare with large number of values switch($catagory) { case &quot;1&quot;: statement1; break; case &quot;2&quot;: statement2; break; case &quot;3&quot;: statement3; break; case &quot;4&quot;: statement4; break; } http://www.php.net/manual
Control flow (cont'd) While loop Specifies a condition that must be met before execution is terminated View example *We will be using 'while loop' in the final project exercise, to read weather data  while (expression) { statements; } //Example: incremental value global $i; $i = 0; while ($i <= 5) { echo &quot;$i <br>&quot;; $i++; } http://www.php.net/manual
Control flow (cont'd) For loop Statement which allows code to be repeatedly executed View example *We will be using 'for loop' in the final project exercise, to perform calculation of cumulative thermal time for (expression1; expression2; expression3) { statements; } //Example: Incremental values global $i; for ($i=0; $i<=5; $i++) { echo &quot;$i <br>&quot;; } http://www.php.net/manual
Functions Consist of:  (1) Function definition, (2) Function implementation  View example   function geo_distance_exercise   view output function definition ------------------------ function function_name (parameters) { statements; } //function definition: converting degrees to radians function rad($deg_in) { $result = $deg_in *(pi()/180); return $result; } //function implementation: converting degrees to radians $radvalue = rad(30.0); echo &quot;radvalue= $radvalue <br>&quot;;  //radvalue= 0.523598775598 function implementation --------------------------------- //value-returning function: $value = function_name(parameters); //non-returning function: function_name(parameters); http://www.php.net/manual
Arrays Series of similar items, accessible via index Index can be integer or string Array size is accessible by using 'count()' function //Basic syntax to access array's item $array_name[index]  = array value Exercise 2: array  Exercise file View output http://www.php.net/manual
File Server Client php codes files php codes files File Reading & Writing Steps:  (1) Connecting file handler to a file (2) Capturing file content (3) Closing file (ending file handler connection to a file) http://www.php.net/manual
File Reading File Reading //assigning file handler to a file $file_handler = fopen(&quot;filename&quot;,&quot;mode&quot;); //capturing file content $var = fgetcsv($file_handler,1000,&quot;,&quot;); //closing file fclose($file_handler); 1000 - maximum char per line mode: r = read only w = write only rt = read only, text file more on modes: http://us3.php.net/manual/en/function.fopen.php http://www.php.net/manual
File Reading (cont'd) File Reading Exercise Exercise file View output Create &quot;input_files&quot; directory in the ftp folder Create date.txt file with the following content: 10 20 30 30 45 http://www.php.net/manual
File Writing File Writing File Writing Exercise Exercise file View output Create &quot;output_files&quot; directory in the ftp folder //assigning file handler to a file $file_handler = fopen(&quot;filename&quot;,&quot;mode&quot;); //writing file fwrite($filehandler,&quot;$variable_to_write&quot;); //closing file fclose($file_handler); mode: w = write only, wt = write only, text file, a = append more on modes: http://us3.php.net/manual/en/function.fopen.php http://www.php.net/manual
File Reading – Multiple Columns Multiple columns of data are common, ie: weather data File Reading Example – Multi Columns View code View output Trick: Create an intermediate 'clean' file (two reading steps) The 'clean' file has a consistent delimited, ie: one space User ereg_replace() function to clean extra white spaces $originalvar = &quot;10  20&quot;; $cleanvar = ereg_replace(' +', ' ', $originalvar); echo &quot;$cleanvar&quot;; // 10 20 10  20 20  40 30  60 30  60 45  90 File to read:  data2.txt http://www.php.net/manual
Combo box Example View this example View code Month: <select name=&quot;month&quot;> <option value=&quot;1&quot;>Jan</option> <option value=&quot;2&quot;>Feb</option> <option value=&quot;3&quot;>Mar</option> <option value=&quot;4&quot;>Apr</option> <option value=&quot;5&quot; Selected>May</option> <option value=&quot;6&quot;>Jun</option> <option value=&quot;7&quot;>Jul</option> <option value=&quot;8&quot;>Aug</option> <option value=&quot;9&quot;>Sep</option> <option value=&quot;10&quot;>Oct</option> <option value=&quot;11&quot;>Nov</option> <option value=&quot;12&quot;>Dec</option> </select> http://www.php.net/manual
Project Exercise Goal   Reading weather file from long-term weather data from NASA Eventually calculate cumulative thermal time (GDU) for a user-given starting and ending dates  Preparation  Download new weather data from  NASA site   *, or use the existing weather data for  Lincoln, NE    * Required lat & long input    Online resource for finding lat long of a location:  itouchmap   Save weather file as text file under your input_files folder http://www.php.net/manual
Project Exercise 1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.php.net/manual
Project Exercise 1 (cont'd) View output   weather data: Lincoln, NE  lat: 40.82, long: -96.65, 1997-2008 To skip a header line, you can assign it to a dummy variable  $header = fgets($file_handler); Additional cleaning step would be needed if there is extra whie space to the left of the first column of the data. You can use the ltrim approach: Example: $array_output[$i] = ltrim($array_output[$i]); The goal is to read tmax and tmin. However, the data contains other weather variables (ie. solar radiation, rh, ect). You can assign dummy variables for the extra variables, or it doesn't hurt to assign each to uniqe variable (in case you would need it for something else) Particular important variable is tmean, not in the data, it's calculated as: Tmean = 0.5 * (Tmax + Tmin) http://www.php.net/manual
Project Exercise 2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.php.net/manual
Project Exercise 2 (cont'd) View output   Table of day of year vs date  Use practically all the component from the previous exercise For day selection combo box, you can use for loop, ie from i=1 to i=31 View Example The conversion from Date to DOY is needed because the user input is date while the weather data is index by year and DOY. View Date to DOY function Use  if statement  to identify starting point (year & doy) to start displaying the output, within a for loop going thru the whole index of data. ie: for ($i=0; $i<=$array_size; $i++) { if (($year_array[$i] == $yearinput) && ($doy_array[$i] >= $doyinput) &&  ($doy_array[$i] < $doyval+9)) { //put output statement here } } Use $_POST['var'] to capture form inputs $yearval = $_POST['year']; $monthval = $_POST['month']; $dayval = $_POST['day']; http://www.php.net/manual
Project Exercise 3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.php.net/manual
Project Exercise 3 (cont'd) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],View output   http://www.php.net/manual
Misc. Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],http://www.php.net/manual

Contenu connexe

Tendances

Tendances (20)

Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Php
PhpPhp
Php
 
Best practices tekx
Best practices tekxBest practices tekx
Best practices tekx
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
ImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlaggingImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlagging
 
Php1
Php1Php1
Php1
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Php string function
Php string function Php string function
Php string function
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
AdvancedXPath
AdvancedXPathAdvancedXPath
AdvancedXPath
 
PHP 5.3 Part 2 - Lambda Functions & Closures
PHP 5.3 Part 2 - Lambda Functions & ClosuresPHP 5.3 Part 2 - Lambda Functions & Closures
PHP 5.3 Part 2 - Lambda Functions & Closures
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 

En vedette

A Newbie's Intro to the Web
A Newbie's Intro to the WebA Newbie's Intro to the Web
A Newbie's Intro to the Webwebhostingguy
 
Tech Brief Questions
Tech Brief Questions Tech Brief Questions
Tech Brief Questions webhostingguy
 
Slide 1 - Free Web Hosting with PHP, MySQL and cPanel
Slide 1 - Free Web Hosting with PHP, MySQL and cPanelSlide 1 - Free Web Hosting with PHP, MySQL and cPanel
Slide 1 - Free Web Hosting with PHP, MySQL and cPanelwebhostingguy
 
Good News, Bad News
Good News, Bad NewsGood News, Bad News
Good News, Bad NewsJeff Green
 
Agcapita January 2012 Briefing
Agcapita January 2012 BriefingAgcapita January 2012 Briefing
Agcapita January 2012 BriefingVeripath Partners
 
"Fully-baked as both an e-mail and
"Fully-baked as both an e-mail and "Fully-baked as both an e-mail and
"Fully-baked as both an e-mail and webhostingguy
 
Agcapita Feb 2010 Agriculture Briefing
Agcapita Feb 2010 Agriculture BriefingAgcapita Feb 2010 Agriculture Briefing
Agcapita Feb 2010 Agriculture BriefingVeripath Partners
 

En vedette (9)

A Newbie's Intro to the Web
A Newbie's Intro to the WebA Newbie's Intro to the Web
A Newbie's Intro to the Web
 
Week 8
Week 8Week 8
Week 8
 
Tech Brief Questions
Tech Brief Questions Tech Brief Questions
Tech Brief Questions
 
Slide 1 - Free Web Hosting with PHP, MySQL and cPanel
Slide 1 - Free Web Hosting with PHP, MySQL and cPanelSlide 1 - Free Web Hosting with PHP, MySQL and cPanel
Slide 1 - Free Web Hosting with PHP, MySQL and cPanel
 
Good News, Bad News
Good News, Bad NewsGood News, Bad News
Good News, Bad News
 
Class 01
Class 01Class 01
Class 01
 
Agcapita January 2012 Briefing
Agcapita January 2012 BriefingAgcapita January 2012 Briefing
Agcapita January 2012 Briefing
 
"Fully-baked as both an e-mail and
"Fully-baked as both an e-mail and "Fully-baked as both an e-mail and
"Fully-baked as both an e-mail and
 
Agcapita Feb 2010 Agriculture Briefing
Agcapita Feb 2010 Agriculture BriefingAgcapita Feb 2010 Agriculture Briefing
Agcapita Feb 2010 Agriculture Briefing
 

Similaire à course slides -- powerpoint

Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQLkalaisai
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9isadorta
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
What Is Php
What Is PhpWhat Is Php
What Is PhpAVC
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в MagentoMagecom Ukraine
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHPKing Foo
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applicationsamichoksi
 

Similaire à course slides -- powerpoint (20)

Php
PhpPhp
Php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Php intro
Php introPhp intro
Php intro
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
PHP
PHP PHP
PHP
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applications
 

Plus de webhostingguy

Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Frameworkwebhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guidewebhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3webhostingguy
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serverswebhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidationwebhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreementwebhostingguy
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...webhostingguy
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructurewebhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.pptwebhostingguy
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy webhostingguy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandiserswebhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Productswebhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mbwebhostingguy
 

Plus de webhostingguy (20)

File Upload
File UploadFile Upload
File Upload
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web servers
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
 
Notes8
Notes8Notes8
Notes8
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
 
OLUG_xen.ppt
OLUG_xen.pptOLUG_xen.ppt
OLUG_xen.ppt
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
 
Reseller's Guide
Reseller's GuideReseller's Guide
Reseller's Guide
 

course slides -- powerpoint

  • 1. Introduction to Web Programming with PHP Scripting Language for Applications in Agricultural Climatology Title
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Input (syntax) Syntax (example): View this example <html> <head> <title>PHP Test</title> </head> <body> <?php if (isset($_POST['submit'])) { echo &quot;Hi, &quot; . $_POST['name']. &quot;! <br/>&quot;; } ?> <form action=&quot;formexample.php&quot; method =&quot;post&quot;> <p> Name: <br/> <input type = &quot;text&quot; name=&quot;name&quot; size =&quot;20&quot; maxlength =&quot;40&quot; value=&quot;&quot; /> </p> <input type=&quot;submit&quot; name = &quot;submit&quot; value&quot;Go!&quot; /> </form> </body> </html> http://www.php.net/manual
  • 10.
  • 11.
  • 12. Data types Boolean (true or false) $variable = false; // $variable is false $variable = 0; // $variable is false $variable = true; // $variable is true $variable = 1; // $variable is true $variable = 5; // $variable is true Any non-zero value – true Integer Whole number, no fractional parts Maximum supported integer size is typicalla 2^31 Float Floating-point number -- contains fractional parts. String Sequence of character treated as a contiguous group http://www.php.net/manual
  • 13. Data types (cont'd) Array Series of similar items. Index collection of data values. Each index (key) references to a corresponding value. Example: member[0] = &quot;John&quot;; member[1] = &quot;Marry&quot;; member[2] = &quot;Suzzie&quot;; http://www.php.net/manual
  • 14. Data types (cont'd) Object Must be explicitly declared: Class -- attribute, function Class definition serves as template and cannot itself be manipulated. Instead, objects are created based on this template -- use 'new' keyword. soybean object is created and can then it attribute can be set by making us of the method setGroup() Class plant { private $group; function setGroup($status){ $this->group = $status; } } $soybean = new plant; $soybean->setGroup(&quot;dicots&quot;); http://www.php.net/manual
  • 15. Type casting Converting one type to the other example: $variable1 = 13; $variable2 = (double) $variable1; // 13.0 $variable1 = 4.2; $variable2 = (int) $variable1; // 4 (truncated, not round) http://www.php.net/manual
  • 16. Variables Scope Local Variables A variable declared in a function is considered local. It can only be referenced in that function. When you exit the function in which a local variable has been declared, that variable and its corresponding value are destroyed. View this example $x = 2; function assignx() { $x = 0; echo &quot;x inside function is $x <br>&quot;; } assignx(); echo &quot;x outside function is $x <br>&quot;; http://www.php.net/manual
  • 17. Variables Scope (cont'd) Global Variables Global variables can be accessed in any part of the program To modify global variabl, it must be explicitly declared to be a global in the function in which itis to be modified. View this example $x = 2; function assignx() { Global $x; $x = 0; echo &quot;x inside function is $x <br>&quot;; } assignx(); echo &quot;x outside function is $x <br>&quot;; http://www.php.net/manual
  • 18. Variables Scope (cont'd) Static Variables Static variable does not lose its value when the function exists. View example without static View example with static function keep_track() { Static $count = 0; $count++; echo &quot;$count <br>&quot;; } keep_track(); keep_track(); keep_track(); http://www.php.net/manual
  • 19. Variables Scope (cont'd) Superglobal Variables Predefined variables View example HTTP_USER_AGENT provide user's browser information For more examples of similar superglobal variables, go to: http://us3.php.net/manual/en/reserved.variables.server.php echo &quot;Your browser is: $_SERVER['HTTP_USER_AGENT']&quot;; http://www.php.net/manual
  • 20. Operators For list of operators in php, go to: http://us3.php.net/manual/en/language.operators.php The list includes: arithmetic operators (*, /, +, -) string operator, ie concatenate with &quot;.&quot; logical operators (&&, ||) equality operators (==, !=) http://www.php.net/manual
  • 21. Control flow Conditional Controlling the flow of execution depending on the specified condition defined by expression Exercise 1: if statement – thermal time calculation Exercise file View output if (expression) { statement; } if (expression) { statement; } else { statement; } if (expression) { statement; } else if (expression) { statement; } else { statement; } http://www.php.net/manual
  • 22. Control flow (cont'd) Conditional Use as variant of if-else combination when need to compare with large number of values switch($catagory) { case &quot;1&quot;: statement1; break; case &quot;2&quot;: statement2; break; case &quot;3&quot;: statement3; break; case &quot;4&quot;: statement4; break; } http://www.php.net/manual
  • 23. Control flow (cont'd) While loop Specifies a condition that must be met before execution is terminated View example *We will be using 'while loop' in the final project exercise, to read weather data while (expression) { statements; } //Example: incremental value global $i; $i = 0; while ($i <= 5) { echo &quot;$i <br>&quot;; $i++; } http://www.php.net/manual
  • 24. Control flow (cont'd) For loop Statement which allows code to be repeatedly executed View example *We will be using 'for loop' in the final project exercise, to perform calculation of cumulative thermal time for (expression1; expression2; expression3) { statements; } //Example: Incremental values global $i; for ($i=0; $i<=5; $i++) { echo &quot;$i <br>&quot;; } http://www.php.net/manual
  • 25. Functions Consist of: (1) Function definition, (2) Function implementation View example function geo_distance_exercise view output function definition ------------------------ function function_name (parameters) { statements; } //function definition: converting degrees to radians function rad($deg_in) { $result = $deg_in *(pi()/180); return $result; } //function implementation: converting degrees to radians $radvalue = rad(30.0); echo &quot;radvalue= $radvalue <br>&quot;; //radvalue= 0.523598775598 function implementation --------------------------------- //value-returning function: $value = function_name(parameters); //non-returning function: function_name(parameters); http://www.php.net/manual
  • 26. Arrays Series of similar items, accessible via index Index can be integer or string Array size is accessible by using 'count()' function //Basic syntax to access array's item $array_name[index] = array value Exercise 2: array Exercise file View output http://www.php.net/manual
  • 27. File Server Client php codes files php codes files File Reading & Writing Steps: (1) Connecting file handler to a file (2) Capturing file content (3) Closing file (ending file handler connection to a file) http://www.php.net/manual
  • 28. File Reading File Reading //assigning file handler to a file $file_handler = fopen(&quot;filename&quot;,&quot;mode&quot;); //capturing file content $var = fgetcsv($file_handler,1000,&quot;,&quot;); //closing file fclose($file_handler); 1000 - maximum char per line mode: r = read only w = write only rt = read only, text file more on modes: http://us3.php.net/manual/en/function.fopen.php http://www.php.net/manual
  • 29. File Reading (cont'd) File Reading Exercise Exercise file View output Create &quot;input_files&quot; directory in the ftp folder Create date.txt file with the following content: 10 20 30 30 45 http://www.php.net/manual
  • 30. File Writing File Writing File Writing Exercise Exercise file View output Create &quot;output_files&quot; directory in the ftp folder //assigning file handler to a file $file_handler = fopen(&quot;filename&quot;,&quot;mode&quot;); //writing file fwrite($filehandler,&quot;$variable_to_write&quot;); //closing file fclose($file_handler); mode: w = write only, wt = write only, text file, a = append more on modes: http://us3.php.net/manual/en/function.fopen.php http://www.php.net/manual
  • 31. File Reading – Multiple Columns Multiple columns of data are common, ie: weather data File Reading Example – Multi Columns View code View output Trick: Create an intermediate 'clean' file (two reading steps) The 'clean' file has a consistent delimited, ie: one space User ereg_replace() function to clean extra white spaces $originalvar = &quot;10 20&quot;; $cleanvar = ereg_replace(' +', ' ', $originalvar); echo &quot;$cleanvar&quot;; // 10 20 10 20 20 40 30 60 30 60 45 90 File to read: data2.txt http://www.php.net/manual
  • 32. Combo box Example View this example View code Month: <select name=&quot;month&quot;> <option value=&quot;1&quot;>Jan</option> <option value=&quot;2&quot;>Feb</option> <option value=&quot;3&quot;>Mar</option> <option value=&quot;4&quot;>Apr</option> <option value=&quot;5&quot; Selected>May</option> <option value=&quot;6&quot;>Jun</option> <option value=&quot;7&quot;>Jul</option> <option value=&quot;8&quot;>Aug</option> <option value=&quot;9&quot;>Sep</option> <option value=&quot;10&quot;>Oct</option> <option value=&quot;11&quot;>Nov</option> <option value=&quot;12&quot;>Dec</option> </select> http://www.php.net/manual
  • 33. Project Exercise Goal Reading weather file from long-term weather data from NASA Eventually calculate cumulative thermal time (GDU) for a user-given starting and ending dates Preparation Download new weather data from NASA site *, or use the existing weather data for Lincoln, NE * Required lat & long input Online resource for finding lat long of a location: itouchmap Save weather file as text file under your input_files folder http://www.php.net/manual
  • 34.
  • 35. Project Exercise 1 (cont'd) View output weather data: Lincoln, NE lat: 40.82, long: -96.65, 1997-2008 To skip a header line, you can assign it to a dummy variable $header = fgets($file_handler); Additional cleaning step would be needed if there is extra whie space to the left of the first column of the data. You can use the ltrim approach: Example: $array_output[$i] = ltrim($array_output[$i]); The goal is to read tmax and tmin. However, the data contains other weather variables (ie. solar radiation, rh, ect). You can assign dummy variables for the extra variables, or it doesn't hurt to assign each to uniqe variable (in case you would need it for something else) Particular important variable is tmean, not in the data, it's calculated as: Tmean = 0.5 * (Tmax + Tmin) http://www.php.net/manual
  • 36.
  • 37. Project Exercise 2 (cont'd) View output Table of day of year vs date Use practically all the component from the previous exercise For day selection combo box, you can use for loop, ie from i=1 to i=31 View Example The conversion from Date to DOY is needed because the user input is date while the weather data is index by year and DOY. View Date to DOY function Use if statement to identify starting point (year & doy) to start displaying the output, within a for loop going thru the whole index of data. ie: for ($i=0; $i<=$array_size; $i++) { if (($year_array[$i] == $yearinput) && ($doy_array[$i] >= $doyinput) && ($doy_array[$i] < $doyval+9)) { //put output statement here } } Use $_POST['var'] to capture form inputs $yearval = $_POST['year']; $monthval = $_POST['month']; $dayval = $_POST['day']; http://www.php.net/manual
  • 38.
  • 39.
  • 40.