0% found this document useful (0 votes)
56 views

Web Engineering Lab 12

The document contains instructions for 3 PHP tasks: 1. Display temperature data with average, lowest 7 temperatures, and highest 7 temperatures. 2. Generate a multiplication table from 1-6 using nested for loops. 3. Generate a chessboard using nested for loops and a function to toggle row colors.

Uploaded by

Eesha Arif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Web Engineering Lab 12

The document contains instructions for 3 PHP tasks: 1. Display temperature data with average, lowest 7 temperatures, and highest 7 temperatures. 2. Generate a multiplication table from 1-6 using nested for loops. 3. Generate a chessboard using nested for loops and a function to toggle row colors.

Uploaded by

Eesha Arif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab 12: PHP Basics

Lab Task

Task 1:
 <!DOCTYPE html>  
<html>   
 <head>   
  <title>Task-3</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  </head>  
  <body>  

  <?php  
    $month_temp = array(78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 81, 76
, 73,  
          68, 72, 73, 75, 65, 74, 63, 67, 65, 64, 68, 73, 75, 79, 73);
    $avg = array_sum($month_temp)/sizeof($month_temp);
    sort($month_temp);
    echo "Average Temperature: $avg <br>";
    echo "List of seven lowest temperatures: ";
    echo implode( ', ', array_slice( $month_temp, 0, 7));
    echo "<br>List of seven largest temperatures: ";
    echo implode(', ', array_slice($month_temp,-7,7));

    ?>  
  </body>
  
</html>

CS-344: Web Engineering Page 1


Task 2:
<!DOCTYPE html>  
<html>  
    <head>   
      <title>Task-2</title>  
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
      <style>
      table, tr,td{
        border: 1px solid black;

      }
      td{
          padding: 5px;
      }
      </style>
      </head>  
    <body> 
    <table>
    <?php
        for ($i=1; $i<=6; $i++){
            echo "<tr>";
            for ($x=1; $x<=5; $x++){
                echo "<td>",$i,"*",$x,"=",$i*$x,"</td>";

            }

CS-344: Web Engineering Page 2


            echo "</tr>";
        }

    ?>
    
    </table>

 
  </body>  
</html>  
    

Task 3
<!DOCTYPE html>  

CS-344: Web Engineering Page 3


<html>   
 <head>   
  <title>Task-3</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  <style>
  table, td{
    border: 1px solid black;
  }
  td{
    width: 60px;
    height: 60px;
  }
  </style>
  </head>  
  <body>   
  <h3>Chess Board - PHP Nested Loops</h3>  
  <!-- cell 270px wide (8 columns x 60px) -->  
  <table>
  <?php
    function toggle($var){
      if($var == true){
        return false;
      }
      return true;
    }
    $black = false;
    for ($i=1; $i<=8; $i++){
      $black = toggle($black);
      echo "<tr>";
      for ($x=1; $x<=8; $x++){
        if ($black){
          echo "<td bgcolor=\"#000000\"></td>";
        }
        else{
          echo "<td bgcolor=\"#ffffff\"></td>";
        }
        $black = toggle($black);

      }
      echo "</tr>";
    }

CS-344: Web Engineering Page 4


  ?>
  
  </table>  
  </body>  
  </html> 

CS-344: Web Engineering Page 5


CS-344: Web Engineering Page 6

You might also like