Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP with HTML.

Similar presentations


Presentation on theme: "PHP with HTML."— Presentation transcript:

1 PHP with HTML

2 Exercise #2

3 Exercise 2-1 Create the a multiplication table from 1-10 1 2 3 4 5 6 7
8 9 10 12 14 16 18 20 15 21 24 27 30 28 32 36 40 25 35 45 50 42 48 54 60 49 56 63 70 64 72 80 81 90 100

4 Exercise 2-2 Sort the array values in descending order using loops 2 4
3 1 5 5 4 3 2 1

5 Exercise 2-3 Display the values from the associative array using foreach loop $EU = array( "Italy"=>"Rome", "Luxembourg"=>"Luxembourg", "Belgium"=> "Brussels", "Denmark"=>"Copenhagen",  "Finland"=>"Helsinki", "France" => "Paris",  "Slovakia"=>"Bratislava) ;

6 Exercise 2-4 Using loops display the following pattern

7 Integrating PHP and HTML

8 PHP & HTML PHP and HTML interact a lot: PHP can generate HTML, and HTML can pass information to PHP <head></head> <body class="page_bg"> Hello, today is <?php echo date('l, F jS, Y'); ?>. </body> </html>

9 PHP & HTML <html> <head></head> <body> <ul>  <?php for($i=1;$i<=5;$i++){ ?> <li>Menu Item <?php echo $i; ?></li>  <?php } ?> </ul>  </body> </html> Menu Item 1 Menu Item 2 Menu Item 3 Menu Item 4 Menu Item 5

10 PHP & HTML Use echo to display HTML tags
<?php echo "<html>"; echo "<head></head>"; echo "<body class=\"page_bg\">"; echo "Hello, today is "; echo date('l, F jS, Y'); //other php code here echo "</body>"; echo "</html>"; ?>

11 Passing value from HTML to PHP using Forms
Use $_GET or $_POST <?php $Fname = $_POST["Fname"]; $Lname = $_POST["Lname"]; ?> <html> <head> <title>Personal INFO</title> </head> <body> <form method="post" action="<?php echo $PHP_SELF;?>">#action refers to the php file First Name:<input type="text" name="Fname"><br /> Last Name:<input type="text" name="Lname"><br /> <input type=‘submit’ value=‘Submit’ /> </form> <? echo "Hello, ".$Fname." ".$Lname.".<br />"; ?>

12 Practice Exercise Create a simple form which accepts the values firstname, lastname, address, , contact number, gender (use dropdowns), age (use number), username, and password (use password). Once submitted it will display a message “Registration is complete”.

13 Practice Assignment Display the key for the associative array
$arr = array(“Cebu”=> “Cebu City”, “Manila”=> “Metro Manila”, “Davao”=“Davao City”); //Display the key on the key value pair Cebu Manila Davao

14 Answers to Exercise #2-1 <?php for($i=1;$i<=10;$i++){ for($j=1;$j<=10;$j++) echo $j * $i . " "; echo "<br />"; } ?>

15 Answers to Exercise #2-2 $sorted = true;
<?php $arr = array(2,4,3,5,1); $sorted = false; while (false === $sorted) { $sorted = true; for ($i = 0; $i < count($arr)-1; ++$i) { $current = $arr[$i]; $next = $arr[$i+1]; if ($next > $current) { $arr[$i] = $next; $arr[$i+1] = $current; } print_r($arr); ?>

16 Answers to Exercise #2-3 <?php foreach($EU as $city){ echo $city . "<br />"; } ?>

17 Answers to Exercise #2-4 <?php
for($i=9;$i>0;$i--){ for($j=1;$j<$i;$j++){ echo "0"; } for($x=$j;$x<10;$x++){ echo "*"; echo "<br />"; ?> <?php for($i=10;$i>0;$i--){ for($j=0;$j<$i-1;$j++){ echo "0"; } for($x=0;$x<(10-$j);$x++){ echo "*"; echo "<br />"; ?>


Download ppt "PHP with HTML."

Similar presentations


Ads by Google