我在 php 中使用循环设计了一个棋盘。棋盘一切都很好,但我无法将棋子放在正确的位置,因为循环,棋盘的每个方格都会重复相同的图片。谁能建议我应该改变什么。请参考我下面的代码。
<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>