P HP a n d My S QL We b De v e l o p me n t...! - S a m s.... -, A & E! (),,. - Cod E- E, PHP...,. -, Te lefonica R& D,,..,.. - B.. PHP MySQL.. PHP... - We b Dyna mic PHP/ MyS QL.. 1,. -, T ntluoma.com.,,,,. PHP MySQL. - twilight3 0, S la s hdot.,,,.. PHP, MySQL,.. - codewa lke rs.com
PHP a n d My SQL We b De v e l o p me n t PHP MyS QL.! - The Inte rnet W rit ing J ourna l! C/ C + + PHP... O' Re illy m S QL a nd My S QL, S QL... -! - ja c kofs ometra de s, PHP MyS QL..,. - PHP.. PHP.. -.... PHP MyS QL.. -..... - C
(Laura Thomson) RMIT, Tangled Web Design. Telstra. ( ) ( ),.. laura@tangledweb.com.au. (Luke Welling) RMIT Tangled Web Design. ( ),.. luke@tangledweb.com.au. (Israel Denis, Jr.). SAPLawson ERP.,.. 1998., Apache, PHP MySQL, GE Procter & Gamble. idenis@ureach.com. (Chris Newman). PHP MySQL.
- PHP MySQL Keele Stoke-on-Trent. 1999 Lightwood Consultancy Ltd..,. http://www.lightwood.net. chris@lightwood.net. Sams.... PHP MySQL.,. esec. 1998 PHP. PHP...,,,,,,,.!.,,,......
5.. : o p e ns o u rc e @s a m s p u b lis h ing.co m : Ma rk Ta b e r As s o c ia t e P u b lis he r S a m s P u b lis h in g 20 1 W e st 10 3 rd S t re e t Ind ia na p o lis, IN 4 6 29 0 US A Sams, www.samspublishing.com. - ISBN. (Errata) www.lukelaura.com www.infopub.co.kr.
D- ROM CD-ROMPHP, MySQL, Apache, PDF. A Apache, MySQL, PHP. CD-ROM. Apache 1.3.27 Software\Apache\Windows\Binary. apache_1.3.27-win32-x86-no_src Apache. MySQL 3.23.54 Software\MySQL\Windows\Binary. SETUP.EXE MySQL. PHP 4.3.0 Software\PHP\Windows\Binary. (php-4.3.0-installer.exe) MySQL PHP.. php-4.3.0-win32.zip, Readme. PDF (PDFlib) Libraries. WinZip. / Apache, MySQL, PHP. A
CD-ROM 7. CD-ROM Apache, MySQL, PHP MySQL. Apache 1.3.27 Software/Apache/Unix/Source. GNU tar httpd-1.3.27.tar.gz, httpd-1.3.27.tar.z. MySQL 3.23.54a Software/MySQL/Unix/Binary. RPM MySQL-3.23.54a-1.i386.rpm MySQL-client-3.23.54a-1.i386.rpm. MySQL. RPM mysql-3.23.54a-pc-linux-i686.tar.gz. MySQL 3.23.54a Software/MySQL/Unix/Source mysql-3.23.54a. tar.gz. Solaris GNU tar. Solaris tar. PHP 4.3.0 Software/PHP/Unix/Source/php-4.3.0.tar.gz. PDF (PDFlib) Libraries. CD- ROM CD-ROM,. CD-ROM.,...... CD-ROM...,.
- P HP MySQ L. PHP MySQL.,. PHP MySQL,? PHP 4,..,. HTML,.....
3 1 PHP MySQL.. PHP.,,.,..,.. HTML,. HTML... PHP MySQL.... PHP MySQL.. PHP MySQL.. 8,,.
2 - PHP MySQL XML... PHP? PHP. HTML PHP. PHP HTML. PHP (Rasmus Lerdorf) 1994.. 2002 10 900 PHP. ( 2003 9 1,300 ). http://www.php.net/usage.php PHP. PHP... PHP Personal Home Page. GNU(GNU = GNU is Not Unix). PHP PHP Hypertext Preprocessor.
3 3 PHP 4.x ( 2003 9, 5.0 ).. PHP http://www.php.net. Zend PHP 4 http://www.zend.com. PHP 4.3 PHP, 4.3. I/O., HTTP, HTTPS, FTP. PEAR. GD. Apache 2. PHP. MySQL? MySQL(-- - ) (RDBMS).,,,. MySQL. MySQL,. MySQL SQL(Structured Query Language). MySQL 1996. 1979. MySQL Linux Journal (Reader's Choice Award). MySQL..
3 4 - PHP MySQL PHP MySQL?.,..,...,.. PHP.,. MySQL.,. Apache IIS( ) 2000,,, PHP MySQL. PHP PHP Perl, ASP, JSP, Allaire (ColdFusion).
3 5 PHP,.. PHP.. Zend Technologies(http://www.zend.com) PHP. PHP. MySQL PostgreSQL, msql, Oracle, dbm, filepro, Hyperwave, Informix, InterBase, Sybase. ODBC(Open Database Connectivity Standard), ODBC. PHP. GIF,. PDF. PHP.
3 6 - PHP MySQL PHP. http://www.php.net PHP. PHP PHP. C Perl. C Perl C++ JavaC, PHP. PHP. FreeBSD PHP. Solaris IRIX. PHP.,.,. MySQL MySQL PostgreSQL, SQL, Oracle. MySQL,.
3 7. MySQL. mysql.com. MySQL. MySQL.. SQL. RDBMS. MySQL. MySQL. PHP MySQL.. P HP PHP.
3 8 - PHP MySQL.. 1 PHP. PHP. PHP,. MySQL MySQL. SQL, PHP MySQL MySQL... PHP MySQL,,. P HP PHP..,,. P HP MySQL. PHP MySQL. PHP MySQL.. PHP MySQL.
a pplication a rgume nt a rticle attribute a udit backs las h browse r ca rdinality ca rriage return, new line case s ens itive ce rtification characte r s et characte r child node collapse column confide ntia l connection consta nt ()
4 0 - PHP MySQL constructor construct contents control structure conve ntion conve rs ion s pecification custome r data hiding decryption default des ign deta il doma in name dummy dynamic ele me nt end tag expa nding expos ure express ion extens ion fetch field filte ring flowcha rt fore ign key form functiona lity ()
1 ha ndle has h header hie ra rchica l hie ra rchy highlight ide ntifie r inde nt index inherita nce insta ntiation integrity interpreter interprete iss ue ite m ite ration leaf node link methodology method mirroring multidime ns iona l multiple chat nest network node norm
4 2 - PHP MySQL note ope ra nd ope rator orde r pa ramete r pa rent node pa rse r pa rty pa rt pass by refe rence pe rforma nce pe rmiss ion pe rsona lization policy polymorphis m precede nce prima ry key principle private key privilege product property prototype public key public method query recovery regular express ion relational a lge bra
3 re lational data bas e re lational theory re mote re pudiation re putation request res et res ource return re use reve rs e s pam ripple effect root node s afe mode sca la r scope script s ecret key s e rve r s ide script s ign sta rt tag s ubclass s ubmit s ubscriber s upe rclass symbol syntax tag
4 - PHP MySQL time sta mp token traffic tra ns action una ry us a bility us e r declare va riable ve rification whites pace
I PHP Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 PHP PHP
PHP 1 PHP PHP. PHP. C ASP. PHP.,. CD-ROM,.,, (expressions) PHP... PHP, i f, el se,? swi t ch., HTML PHP.. HTMLPHP
4 8 PART I PHP i f, el se, swi t ch whi l e, do, f or PHP PHP.,. PHP. PHP A PHP, MySQL. CD-ROM NTPHP. : Bob's Auto Parts PHP HTML. Bob's Auto Parts PHP. Bob CD-ROM chapt er 01. Bob ([1.1] ).. Bob,.
Chapter 1 PHP 4 9 [ 1.1] Bob,. [ 1.1] orderf orm.ht ml - HTML <for m act i on="pr oces sor der.php " met hod=post > <t abl e bor der=0> <t r bgcol or =#cccccc> <t d wi dt h=150>it em</ t d> <t d wi dt h=15>quant it y</ t d> </ t r > <t r > <t d>ti r es</ t d> <td al ign="cent er "><input t ype="t ext " name="t i reqt y" si ze="3" maxl engt h="3"></ t d> </ t r > <t r > <t d>oi l </ t d> <t d al ign="cent er "><input t ype="t ext " name="oi lqt y" si ze="3" maxl engt h="3"></ t d> </ t r > <t r > <t d>spark Pl ugs</ t d> <td al ign="cent er "><input t ype="t ext " name="sparkqt y" si ze="3" maxl engt h="3"></ t d> </ t r > <t r > <td colspan="2" al ign="cent er "><input t ype="submit " value="submit Order "></ t d> </ t r > </ t abl e> </ f orm>
5 0 PART I PHP [ 1.1]. act i on PHP.. act i on URL. URL, met hod get URL post. t i r eqt y, oi l qt y, spar kqt y (f i el d). PHP. HTML f i el d23.., _. act i on pr ocessorder.php.. <ht ml > <head> <t i t l e>bob ' s Aut o Part s - Order Resul t s</ t i t l e> </ head> <body> <h1>bob ' s Aut o Part s</ h1> <h2>or der Resul t s</ h2> </ body> </ ht ml > HTML, PHP. HTMLPHP <?php echo ' <p>or der pr oces sed.</ p> ' ;?>
Chapter 1 PHP 5 1 Bob. [1.2]? [ 1.2] PHP echo. PHP. <ht ml > <head> <t i t l e>bob ' s Aut o Part s - Order Resul t s</ t i t l e> </ head> <body> <h1>bob ' s Aut o Part s</ h1> <h2>or der Resul t s</ h2> <p>order pr ocessed.</ p></ body> </ ht ml > PHP PHP. PHP HTML PHP. PHP JavaScript. pr oces sor der.php.
5 2 PART I PHP HTML PHP PHP. HTML. PHP PHP <?php?>. HTML < >. PHP. PHP PHP PHP HTML. PHP HTML.. PHP PHP. XML <?php echo ' <p>or der pr oces sed.</ p> ' ;?> PHP 3 4. XML SML. <? echo ' <p>or der pr oces sed.</ p> ' ;?> SGML. conf i g shor t _t ags, PHP. A.
Chapter 1 PHP 5 3 <scr i pt l anguage= ' php ' > echo ' <p>or der pr ocess ed. </ p> ' ; </ s cr i pt > JavaScript VBScript. HTML. AS P <%echo ' <p>or der pr oces sed.</ p> ' ; %> ASP conf i g asp_t ags. ASP, ASP PHP. PHP PHP PHP PHP.. echo ' <p>or der pr oces sed.</ p> ' ; echo. [1.2]. echo. C JavaPHP..,, (whitespace). HTML PHP PHP. HTML. <h1>wel come t o Bob ' s Aut o Part s!</ h1><p>what woul d you l i ke t o order t oday?</ p> <h1>wel come Aut o Par t s!</ h1> t o Bob ' s
4 PART I PHP <p>what would you li ke t o or der t oday?</ p> HTML. HTML, PHP. PHP., echo ' hel l o ' ; echo ' wor l d ' ; echo ' hel l o ' ; echo ' wor l d ' ;..,,,. PHP. PHP. PHP (parser). PHP C, C++. PHP C. / * : Bob Smi t h : 4 10. */ / * */. C. C++. echo ' <p>or der pr oces sed.</ p> ' ; / /.
Chapter 1 PHP 5. echo ' <p>or der pr oces sed.</ p> ' ; #. PHP. HTML.... pr ocessor der.php. <?php echo ' <p>order processed at ' ; echo dat e (' H:i, j S F' ) ; echo ' </ p>' ;?> PHP dat e (). [ 1.3].. [ 1.3] PHP date().
5 6 PART I PHP dat e (). PHP... dat e (' H:i, j S F' )... date() dat e ().. H 24, i ( ) (01 ). j 0. S ( t h ), F (, 1 Jan January ).. PHP PHP php.ini. PHP PHP. PHP $ ($!). PHP.,,. t i r eqt y. $t i r eqt y / / $_POST[ ' t i r eqt y ' ] / / $HTTP_POST_VARS [ ' t i r eqt y ' ] / /
Chapter 1 PHP 5 7. PHP. PHP. r egi st er_gl obal s ( ).. PHP 4.1.0....... $t i r eqt y. t i r eqt y $t i r eqt y. r egi st er_gl obal s. PHP 4.2,.,.. $_POST, $_GET, $_REQUEST. $_POST $_GET, POST $_POST, GET $_GET. POST GET $_REQUEST. POST t i r eqt y $_POST [ ' t i r eqt y ' ]. GET $_GET[ ' t i r eqt y ' ]. $_REQUEST [ ' t i r eqt y ' ].
5 8 PART I PHP. PHP $_POST $_GET $HTTP_POST_VARS $HTTP_GET_VARS. PHP. $_REQUEST. $HTTP_POST_VARS [ ' t i r eqt y ' ] $HTTP_GET_VARS [ ' t i r eqt y ' ]..... (PHP = ). $HTTP_POST_VARS [ ' t i r eqt y ' ] $t i r eqt y. $t i r eqt y = $HTTP_POST_VARS [ ' t i r eqt y ' ] ;.. HTML.. <?php / /. $t i r eqt y = $HTTP_POST_VARS [ ' t i r eqt y ' ] ; $oi l qt y = $HTTP_POST_VARS[ ' oi l qt y ' ] ; $spar kqt y = $HTTP_POST_VARS [ ' spar kqt y ' ] ;?> $t i r eqt y, $oi l qt y, $spar kqt y POST..
Chapter 1 PHP 9 echo ' <p>your or der i s as f ol l ows : </ p> ' ; echo $t i reqt y. ' t i res<br / >' ; echo $oi l qt y. ' bot t l es of oi l <br / >' ; echo $spar kqt y. ' spar k pl ugs<br / > ' ; [1.4].. [ 1.4] processorder.php.. echo.. echo $t i reqt y. ' t i res<br / >' ;. (string concatenation operator). echo. echo... echo "$t i reqt y t i res<br / >";
0 PART I PHP.. (" ) ( ' ).. echo ' $t i r eqt y t i r es<br / > ' ; "$t i r eqt y t i r es<br / >".. echo... $t i r eqt y, t i r es<br / >.. PHP. (identifier)..,, `_, $. $. Variable Variables.. PHP. $t i r eqt y $Ti r eqt y..,. HTML.
Chapter 1 PHP 6 1. =.., Bob. 0. PHP. $t ot al qt y = 0; $tot al amount = 0. 00;.. $t ot al qt y = 0; $t ot al amount = $t ot al qt y; (type). PHP -,. -. -. PHP 4, NULL, r esour ce. NULL NULL. r esour ce. r esour ce.
2 PART I PHP PHP PDF phfdoc pdfi nfo. PHP (type strength). PHP. $t ot al qt y $t ot ql amount. $t ot al qt y = 0; $t ot al amount = 0. 00; $t ot al qt y 0 $t ot al qt y. $t ot ql amount.. $t ot al amount = ' Hel l o ' ; $t ot al amount. PHP.. PHP. (type casting). C.. $t ot al qt y = 0; $t ot al amount = (doubl e) $t ot al qt y; $t ot al qt y $t ot al amount. $t ot al amount $t ot al qt y.
Chapter 1 PHP 6 3 Variable Variables PHP var i abl e var i abl e. var i abl e var i abl es. (.. PHP.),. $var name = ' t i r eqt y ' ; $t i r eqt y $$var name. $t i r eqt y. $$varname = 5;. $t i r eqt y = 5;. var i abl e var i abl es.... def i ne ( ' TI REPRI CE', 100) ; def i ne ( ' OI LPRI CE', 10) ; def i ne ( ' SPARKPRI CE', 4) ;. C (C PHP )..
4 PART I PHP. $.. echo TIREPRICE;. phpi nfo (). phpi nf o () ; phpi nfo () PHP. (scope). PHP..... PHP 4.2$_GET $_POST.. $GLOBALS - $_SERVER - $_GET - GET $_POST - POST $_COOKI ES -
Chapter 1 PHP 6 5 $_FI LES - $_ENV - $_REQUEST - $_SESSI ON -.. (operator).. =.,.., =,. (operand). (arithmetic operator). [ 1.1] PHP + - * / % $a + $b $a - $b $a * $b $a / $b $a %$b. $r esul t = $a + $b ;
6 6 PART I PHP $a $b /. - ( ).. $a = - 1;, * /. $a $b.. $a = 27; $b = 10; $r esul t = $a%$b ; $r esul t 27 10 7.. e E. PHP, 0... $a = "Bob ' s "; $b = ' Aut o Par t s ' ; $r esul t = $a. $b ;. $r esul t Bob ' s Aut o Par t s. =, ~ ~. $t ot al qt y = 0;
Chapter 1 PHP 7 $t ot al qt y 0... $a + $b $a $b. 0. $a = 0. $b = 6 + ($a =5) ; $b 11,... $a += 5 ; $a = $a + 5 ;.. [ 1.2].
6 8 PART I PHP [ 1.2] PHP += -= *= /= %=.= $a += $b $a -= $b $a *= $b $a /= $b $a %= $b $a.= $b $a = $a + $b $a = $a - $b $a = $a * $b $a = $a / $b $a = $a %$b $a = $a. $b (++) (- -) += - =.. $a = 4; echo ++$a ; ++. $a 1 5 5. $a ++ ( ). $a = 4; echo $a++; $a. 4 $a 5. - - ++ - - 1. PHP 4 &.. $a = 5; $b = $a;
Chapter 1 PHP 9 $a $b. $a $b. $a = 7; / / $b 5. &. $a = 5; $b = &$a ; $a = 7; / / $a $b 7.. t r ue fal se. ==. $a == $b $a $b. t r ue, fal se. = 0 t r ue, 0f al se. $a = $b t r ue. $a = 5; $b = 7; $a = $b 70 t r ue. $a == $b fal se... PHP. [ 1.3].
70 PART I PHP PHP 4 identical ( === ), t r ue. [ 1.3] PHP = = = ==!= <> < > <= >= identical $a = = $b $a = == $b $a!= $b $a <> $b $a < $b $a > $b $a <= $b $a >= $b., $a 0 100. $a >=0 $a <=100 AND. $a >= 0 &&$a <=100 PHP AND, OR, XOR(exclusive or), NOT. [ 1.4] PHP! NOT!$b $b fal set rue. && AND $a &&$b $a $b t ruet rue. OR $a $b $a $b t ruet rue. and AND $a and $b &&. or OR $a or $b. and or &&..
Chapter 1 PHP 7 1. PHP [ 1.5]. [ 1.5] PHP & AND $a &$b $a $b 1 1. OR $a $b $a $b 1 1. ~ NOT ~$a $a 0 1, 1 0. ^ XOR $a ^ $b $a $b 1 1. << $a << $b $a $b. >> $a >> $b $a $b..,. new - >,, 6. []. =>, 3. (ternary operator).? : C.? : i f- el se,. ($gr ade > 50? ' Pas s ed ' : ' Fai l ed ' ) ;
2 PART I PHP $gr ade 50 Fai l ed'. (error suppression operator). @. $a = @(57/ 0) ; @ 0 @.. PHP t r ack_er r or s $php_er r ormsg. (execution operator) ` ` ` ( ') ~'. PHP ` `. ` `.. $out = `l s - l a ` ; echo ' <pr e>'. $out. ' </ pr e> ' ;. $out = `di r c : ` ; echo ' <pr e>'. $out. ' </ pr e> ' ; C. : PHP Bob.
Chapter 1 PHP 73 PHP. $t ot al qt y = 0; $t ot al qt y = $t i r eqt y + $oi l qt y + $spar kqt y; echo ' I t ems or der ed : '. $t ot al qt y. ' <br / > ' ; $tot al amount = 0. 00; def i ne ( ' TI REPRI CE', 100) ; def i ne ( ' OI LPRI CE', 10) ; def i ne ( ' SPARKPRI CE', 4) ; $t ot al amount = $t i r eqt y * TI REPRI CE + $oi l qt y * OI LPRI CE + $spar kqt y * SPARKPRICE; echo ' Subt ot al : $ '.number_ f or mat ($t ot al amount, 3). ' <br / > ' ; $t axr at e = 0. 10; / / 10%. $t ot al amount = $t ot al amount * (1 + $t axr at e ) ; echo ' Tot al i ncl udi ng t ax : $ '.number_ f or mat ($t ot al amount, 2). ' <br / > ' ;. [1.5]. [ 1.5].
74 PART I PHP. + *.. number_ format (). PHP Mat h.. $t ot al amount = $t i r eqt y * TI REPRI CE + $oi l qt y * OI LPRI CE + $spar kqt y * SPARKPRICE;?. : (precedence). (associativity). [ 1.6].. [ 1.6], or xor and pr i nt = += - = *= / =.= %= &= = ^= ~= <<= >>=? :
Chapter 1 PHP 75 [ 1.6] && ^ & ==!= === < <= > >= << >> + -. * / %! ~ ++ - - (i nt ) (doubl e ) (st r i ng ) (ar r ay ) (obj ect ) @ [] new () (, ). (, ).. $t ot al amount = $t ot al amount * (1 + $t axr at e ) ;. $t ot al amount = $t ot al amount * 1 + $t axr at e ;. 1+$t axr at e. PHP..
76 PART I PHP get t ype () set t ype () ( ). st r i ng get t ype (mi xed var ) ; bool set t ype (mixed var, st ring t ype ) ; get t ype () get t ype () unknown t ype. i nt eger, doubl e, st r i ng, ar r ay, obj ect. set t ype (). $a = 56; echo get t ype ($a ). ' <br / > ' ; s et t ype ($a, ' doubl e ' ) ; echo get t ype ($a ). ' <br / > ' ; get t ype () $a set t ype (). PHP, t r ue fal se. i s_ar r ay () i s_doubl e (), i s_f l oat (), i s_r eal () ( ) i s_l ong (), i s_i nt (), i s_i nt eger () ( ) i s_st r i ng () i s_obj ect () PHP. i sset (). bool ean i s set (mi xed var ) ;
Chapter 1 PHP 7 t r ue, fal se. unset (). voi d uns et (mi xed var ) ; unset () t r ue. empt y (),,, 0 t r ue, f al se. bool ean empt y (mi xed var ) ;,.. echo i ss et ($t i r eqt y) ; echo i sset ($not here) ; echo empt y ($t i r eqt y) ; echo empt y ($not her e) ;. $t i r eqt y i sset () t r ue, empt y (). $not her e i sset () fal se empt y () t r ue.. (type casting).. i nt i ntval (mixed var ) ; float doubl eval (mixed var ) ; st r i ng st rval (mi xed var ) ;
8 PART I PHP. mi xed. mi xed.. (br anchi ng).... if i f. i f, t r uei f.,,..!. i f. i f ( $t ot al qt y == 0 ) echo ' You di d not order anyt hing on t he previ ous page!<br / >' ; $t ot al qt y == 0.. $t ot al qt y ==0 t r ue$t ot al qt y 0. $t ot al qt y 0 fal se. t r ueecho.
Chapter 1 PHP 79 i f. i f. {, }. i f ( $t ot al qt y == 0 ) { echo ' <f ont col or =r ed>' ; echo ' You di d not order anyt hi ng on t he previ ous page!<br / >' ; echo ' </ f ont >' ; } {, }. t r ue f al se. PHP. i f.. else. el se i f fal se. Bob... i f ( $t ot al qt y == 0 ) { echo ' You di d not order anyt hi ng on t he previ ous page!<br / >' ; } el s e { echo $t i reqt y. ' t i res<br / >' ; echo $oi l qt y. ' bot t l es of oi l <br / >' ; echo $spar kqt y. ' spar k pl ugs<br / > ' ; }
8 0 PART I PHP i f i f.. i f ( $t ot al qt y == 0) { echo ' You di d not order anyt hing on t he previ ous page!<br / >' ; } el s e { i f ( $t i r eqt y>0 ) echo $t i r eqt y. ' t i r es<br / > ' ; i f ( $oi lqt y>0 ) echo $oi l qt y. ' bot t l es of oi l <br / > ' ; i f ( $sparkqt y>0 ) echo $spar kqt y. ' spar k pl ugs<br / > ' ; } elseif. el sei f. t r ue... 10-0% 10~49-5% 50~99-10% 100-15% i f el si ef. AND (&&). i f ( $t i r eqt y < 10 ) $di scount = 0; el s ei f ( $t i r eqt y >= 10 && $t i r eqt y <= 49 ) $di scount = 5; el s ei f ( $t i r eqt y >= 50 && $t i r eqt y <= 99 ) $di scount = 10; el s ei f ( $t i r eqt y >= 100 ) $di scount = 15;
Chapter 1 PHP 8 1 el sei f el se i f. el se i f i f. t r ue, t r ue. switch swi t ch i f. i f t r ue f al se, swi t ch (,, ). case case de faul t case. Bob. <t r > <t d>how di d you f i nd Bob ' s</ t d> <t d><s el ect name="f i nd"> <opt ion val ue = "a">i ' ma regul ar cust omer <opt i on val ue = "b">tv adver t i si ng <opt ion val ue = "c">phone di rect ory <opt ion val ue = "d">word of mout h </ s el ect > </ t d> </ t r > [ 1.6] Bob s Auto Part
2 PART I PHP HTML a, b, c, d. i f el se i f. i f ($f i nd == ' a ' ) echo ' <p>regul ar cust omer. </ p> ' ; el s ei f ($f i nd == ' b ' ) echo ' <p>cust omer r ef er r ed by TV adver t. </ p> ' ; el s ei f ($f i nd == ' c ' ) echo ' <p>cust omer r ef er r ed by phone di r ect or y. </ p> ' ; el s ei f ($f i nd == ' d ' ) echo ' <p>cust omer r ef er r ed by wor d of mout h.</ p> ' ; swi t ch. swi t ch ($f i nd) { cas e ' a ' : echo ' <p>regul ar cust omer. </ p> ' ; br eak; cas e ' b ' : echo ' <p>cust omer r ef er r ed by TV adver t. </ p> ' ; br eak; cas e ' c ' : echo ' <p>cust omer r ef er r ed by phone di r ect or y. </ p> ' ; br eak; cas e ' d ' : echo ' <p>cust omer r ef er r ed by wor d of mout h.</ p> ' ; br eak; def aul t : echo ' <p>we do not know how thi s cust omer found us. </ p>' ; br eak; } swi t ch i f el se i f. i f swi t ch case br eak. br eak case t r ue. br eak swi t ch..
Chapter 1 PHP 8 3. el se, el sei f, swi t ch if... ( )... [1.7]. [ 1.7] [ 1.2] HTML. [ 1.2] f rei ght.ht ml - <ht ml > <body> <t abl e bor der="0" cel l paddi ng="3"> <t r > <t d bgcol or="#cccccc" al ign="cent er ">Di st ance</ t d> <t d bgcol or="#cccccc" al ign="cent er ">Cost </ t d> </ t r >
8 4 PART I PHP <t r > <td al ign="right ">50</ td> <td al ign="right ">5</ t d> </ t r > <t r > <td al ign="right ">100</ t d> <td al ign="right ">10</ td> </ t r > <t r > <td al ign="right ">150</ t d> <td al ign="right ">15</ td> </ t r > <t r > <td al ign="right ">200</ t d> <td al ign="right ">20</ td> </ t r > <t r > <td al ign="right ">250</ t d> <td al ign="right ">25</ td> </ t r > </ t abl e> </ body> </ ht ml >.. while PHPwhi l e i f. whi l e i f whi l e t r ue. whi l e f al se for. whi l e. whi l e ( condi t i on ) expr ess i on; whi l e 1 5.
Chapter 1 PHP 5 $num = 1; whi l e ($num<= 5 ) { echo $num. "<br / >"; $num++; } fal sewhi l e. whi l e [1.7]. [ 1. 3] f rei ght.php - PHP Bob <body> <t abl e bor der="0" cel l paddi ng="3"> <t r > <t d bgcol or="#cccccc" al ign="cent er ">Di st ance</ t d> <t d bgcol or="#cccccc" al ign="cent er ">Cost </ t d> </ t r > <? $di st ance = 50; whi l e ($di st ance <= 250 ) { echo "<t r>\ n <t d al ign"="right ">$dist ance</ td>\ n"; echo " <t d al ign="right ">". $dist ance / 10. "</ td>\ n</ t r>\ n"; $di st ance += 50; }?> </ t abl e> </ body> </ ht ml > HTML.. [ 1.3] (\ n). (") HTML<br >.
8 6 PART I PHP for foreach whi l e for. for. f or ( expr essi on1; condi t i on ; expr es si on2) expr es si on3; exp r es s i on1.. condi t i on fal se. exp r es si on2. expr ess i on3.. [ 1.3]whi l e f or. <? for ($di st ance = 50; $di st ance <= 250; $di st ance += 50) { echo "<t r >\ n <t d al i gn= ' r i ght ' >$di st ance</ t d>\ n"; echo " <t d al i gn= ' r i ght ' >". $di st ance / 10. "</ t d>\ n</ t r >\ n"; }?> whi l e for for. for var i abl e var i abl e 5., name1, name2, name3. for ($i=1; $i <= $numnames ; $i++) { $t emp= "name$i "; echo $$t emp. ' <br / >' ; / /. }
Chapter 1 PHP 8 7. for each for 3. do..while do...whi l e.. do expr es si on; whi l e ( condi t i on ) ; do...whi l e whi l e. do...whi l e. t rue. $num= 100; do { echo $num. ' <br / > ' ; } whi l e ($num < 1 ) ;. swi t ch br eak. br eak. cont i nue. PHP exi t. exi t. exi t.
8 8 PART I PHP i f ( $t ot al qt y == 0) { echo ' You di d not order anyt hing on t he previ ous page!<br / >' ; exi t ; } exi t PHP. :.