PHP chess board : how to make ?


As we have learned much of the basics of  HTML and CSS. Let us now learn how can we make our web applications more user friendly, flexible and versatile, using php.
Today we will see how to make a chess board using php in collaboration with HTML and CSS
So, Let's start:

BASIC php SYNTAX:

  • Starting Closing Tags:
              <?php

              ?>
        Php code must be written in these tags.
  • Variables:
             Start with "$" sign e.g. $num=3;

             ; is really important to put after every statement.
  • Functions:
             Functions start with the keyword "function". E.g. function power(){}
  • Print:
            echo "printing by using echo";
            echo ("printing by using echo");
            print "printing by using print";
            print ("echo "printing by using print");


CODE:

<!DOCTYPE html>  
<html>   
 <head>   
  <title>Task-3</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  </head>  
  <body>   
  <h3>Chess Board - PHP Nested Loops</h3>  
 <!-- cell 270px wide (8 columns x 60px) -->  
      <?php  
      
  function chessBoardMaker()
        {
            
            echo "<table style='border: 1px solid black; border-collapse: collapse;'>";
            
            for($row=1; $row<9; $row++){
                
                echo "<tr> \n";
                
                    for($column=1; $column<9; $column++){
                        
                        $sum = $column + $row;
                        
                        if( $sum % 2 == 0 ){
                
                        
                            echo "<td  style='border: 1px solid black; padding: 20px;' bgcolor= 'black';></td> \n";
                             
                        }
                        
                        else{
                            
                            echo "<td  style='border: 1px solid black; padding: 20px;' bgcolor= 'white';></td> \n";
                        }
                        
                        
                    }
                echo "</tr>";
            }
    
            
            echo "</table>";
            
            }
      
      chessBoardMaker();
  
      
          ?>  
 
  </body>  
  </html> 
-----------------------------------------------------------------------------------------

OUTPUT:






Comments

Popular posts from this blog

1-Machine Learning : Start...

Data Engineering Tools

A Survey of the Final Year University Students

Five People to Follow on Social Media

How to take notes in Freshman Year ?

Web Applications

Web Services : AWS (Amazon Web Services)

Data Analysis : Reading Habit Analysis

E-Commerce : Platforms

Applications of Data Engineering