Digital Media Technology Week 13. □ Dynamic and interactive webpages □ Embedded in HTML □...
-
Upload
isabella-cannon -
Category
Documents
-
view
218 -
download
1
Transcript of Digital Media Technology Week 13. □ Dynamic and interactive webpages □ Embedded in HTML □...
□ Variables
$name = “Oscar Wilde” ; $number = 10 ;
□ Operators
$sentence = $name . “ has written ”. $number . “ plays.” ;
$half = $number / 2 ;$double = $number * 2 ;
Interactive Website
HTML form
PHPscriptUser information
<html><head><title>Databases and Webprogramming</title></head><body bgcolor="#99CCFF" text="#000000">
<form action="action.php" method="get">Enter e-mail address : <br><input type="text" name=" email" size="25"> <BR><input type="submit" value=“CHECK!"> </p></form>
</body></html>
A Form in HTML
method=“get” :
http://132.229.155.189/2007-2008/ [email protected]
method=“post” :
http://132.229.155.189/2007-2008/action.php
<html><head><title>Databases and Webprogramming</title></head><body bgcolor="#99CCFF" text="#000000">
<form action="action.php" method="get">Enter e-mail address : <br><input type="text" name="email" size="25"> <BR><input type="submit" value=“CHECK!"> </p></form>
</body></html>
A Form in HTML
Form data processed by PHP script
□ A so-called superglobal array will be created, depending on the method specified:
$_GET or $_POST ;
□ Names specified can be used to refer to the values, e.g.:
$_GET[“email”] ;
$_POST[“email”] ;
action.php :
<html><head><title>DBWP</title></head><body bgcolor="#99CCFF" text="#000000">
<?php$email = $_GET[“email”] ;print "<p>You have typed in this e-mail address: $email.</p>" ;?>
</body> </html>
Validation of user input:
example
read input
Y Ncontains ‘@’ ?
write ‘email is correct’
write ‘email is not valid’
Conditional Structures: Selection
$email = “[email protected]” ; if ( eregi ( “@”, $email) ){
print “Email is correct.” ; }else{
print “Email is not valid. ; }
read language
Y NEnglish?
Write ‘Welcome!
’Y N
German?
French?Write ‘Wil-
kommen!’
Multiple choices
Conditional Structures: Selection
if ( condition ){
[ code block 1 ] }elseif ( condition ){
[ code block 2 ]}else{
[ code block 3 ]}
<select><option>Select...</option><option value="">option 1</option><option value="">option 2</option></select>
HTML Form Elements
Pull-down menus
<form action=“welcome.php" method="get">
<select name="language"><option> -- Choose a language -- </option><option value="dut">Nederlands</option><option value="eng">English</option><option value="fre">Français</option><option value="ger">Deutsch</option><option value="ita">Italiano</option></select>
<BR><input type="submit" value="GO!">
</p></form>
this file in a browser
$language = $_GET["language"] ;
if ( $language == "dut“ ){ print "Welkom op deze website!"; }elseif ( $language == “eng" ){ print "Welcome to this website!"; }elseif ( $language == “fre" ){ print "Bienvenue sur le site!"; }elseif ( $language == “ger" ){ print "Willkommen auf der Website!"; }elseif ( $language == “ita" ){ print "Benvenuto al questo site!"; }else{ print "Please choose a language first!"; }
$title = "Waiting for
Godot";
$titles = array ("Waiting for Godot", "Endgame", "Happy
Days", “Krapp’s Last Tape" );
Arrays
<?php$titles = array ("The Life of Dr. Boerhaave", "First Principles of Typography", "Florentissima Brittanniae Urbs ", "Digital Access to Book Trade Archives" ) ;?>
□ Used to define a collection / a list□ Can be declared with the array()
function
Use of the array() function in this way will create an automatic index
0 The Life of Dr. Boerhaave
1 First Principles of Typography
2 Florentissima Brittanniae Urbs
3 Digital Access to Book Trade Archives
Addressing elements in the array
<?$books = array ("The Life of Dr. Boerhaave", "First Principles of Typography", "Florentissima Brittanniae Urbs", "A relation of a Voyage to the Army") ;
print $books[1]
?>
An indexed array :
$capitals = array( "Italy"=> "Rome", "Luxembourg"=> "Luxembourg", "Belgium"=> "Brussels", "Denmark"=> “Copenhagen", "Finland"=> "Helsinki", "France"=> "Paris", "Slovakia"=> "Bratislava", "Slovenia"=> "Ljubljana", "Germany"=> "Berlin” ) ;
Addressing an element in an indexed array :
$capitals = array( "Italy"=> "Rome", "Luxembourg"=> "Luxembourg", "Belgium"=> "Brussels” ) ;
print $capitals["Italy"] ;
// this will print "Rome"
Counting the number of elements in an array
<?$books = array ("The Life of Dr. Boerhaave", "First Principles of Typography", "Florentissima Brittanniae Urbs", "Digital Acces to Booktrade Archives") ;
$number = count($books) ;
?>
Navigating arrays
$books = array("Heart of Darkness", "The Picture of Dorian Grey", "The Last September" );
foreach ($books as $b){
print " <p> $b </p> “ ; }