Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:16:48+00:00 2026-06-04T11:16:48+00:00

I have designed a chess board using loops in php. The board is all

  • 0

I have designed a chess board using loops in php. The board is all well, but I cannot get the chess pieces in right position, because of loops, same picture repeats in every squares of the chess boards. Can anyone suggest me what should I change. Please refer to my codes below.

<html>
<head>
<style>
th{
   width:80px;
   height:80px;
}
table{
   border: 5px solid orange;
   border-collapse:collapse;
}
td{
   width:80px;
   height:80px;
}
tr{
   width:80px;
   height:80px; 
}
h1{
   color:#6633FF;
}
</style>

<script type="text/javascript">

</script>
</head>
<body>
<?php
   echo"<h1 align='center'>SAJID Chess Board</h1>";

   echo"<table border='1' align='center'>";

   //Nested For loop starts
   for($i=1; $i<5; $i++)//this is the iteration construct starts from here
{
   echo"<tr>";
   for ($j=7; $j>=0; $j--) // For loop for 1st row

   {
   if(($j%2)==0){
   echo"<td bgcolor='grey'>";
   echo"<img src='king.gif'/>"; //here is the problem, the image of king throughout the chess board                 
   }
  else{
  echo"<td bgcolor='white'>";
  }

  echo"</td>";
  }//for loop ends
  echo "</tr>";

  echo "<tr>";

  for($j=0; $j<8; $j++){ // For loop for 2nd row

  if(($j%2)==0){
  echo"<td bgcolor='grey'>";
  }
  else{
  echo"<td bgcolor='white'>";
  }

  echo"</td>";
  }//for loop ends

  echo "</tr>";

  }//nested for loop ends

echo "</table>";

?>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:16:50+00:00Added an answer on June 4, 2026 at 11:16 am

    You need to redesign your loops, for the correct coordinates,

    Here is an example ive wrote for you

     <html>
        <head>
            <style>
                th{
                    width:80px;
                    height:80px;
                }
                table{
                    border: 5px solid orange;
                    border-collapse:collapse;
                }
                td{
                    width:80px;
                    height:80px;
                }
                tr{
                    width:80px;
                    height:80px; 
                }
                h1{
                    color:#6633FF;
                }
            </style>
    
            <script type="text/javascript">
    
            </script>
        </head>
        <body>
            <?php
    
              // Format $pictures[Row][Column];
              $pictures = array();
    
    
    
              //Row 1
              $pictures[1][1] = "Castle";
              $pictures[1][2] = "Horse";
              $pictures[1][3] = "Bishop";
              $pictures[1][4] = "King";
    
              //Row 2
               $pictures[2][1] = "Pawn";
               $pictures[2][2] = "Pawn";
               $pictures[2][3] = "Pawn";
               $pictures[2][4] = "Pawn";
               $pictures[2][5] = "Pawn";
               $pictures[2][6] = "Pawn";
               $pictures[2][7] = "Pawn";
               $pictures[2][8] = "Pawn";
    
    
    
    
                echo"<h1 align='center'>SAJID Chess Board</h1>";
                echo"<table border='1' align='center'>";
    
    
                for($i = 1; $i <= 8; $i++)
                {     
                    echo "<tr>";
                    for($j = 1; $j <=8; $j++)
                    {
                        if( ($i+$j)%2 )
                        {
                            echo"<td bgcolor='grey'>";
    
    
                        }
                        else
                        {
                            echo"<td bgcolor='white'>";
                        }
    
    
                        if(isset($pictures[$i][$j]))
                            echo $pictures[$i][$j];
    
                        echo "</td>";
                    }
                    echo "</tr>";
                }
    
    
                echo "</table>";
    
            ?>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed a webpage using HTML and client side validation using JavaScript.PHP for
I have designed a form using labels and textboxes and included validation but when
I have designed a custom section handler before but I'm faced with a problem
I have designed one sign-up form,in this form after getting all necessary values I
I have designed the screen using this relative layout. <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android
I have designed a standalone application using swings which can read data from HID
I have designed a form where the user can enter his comment using Add
I have designed several animated Panel s in C# that all inherit from one
I have designed a chat application where different users can create the account, but
I have designed and developed more than 10 sites, but I still have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.