I have to make a star-shaped star using for the loop inside the table. It must have <td> spaces before and after the stars to move around and make them centered , so it looks like a diamond. How can I do it? (I used PHP inside the HTML code.)
Code without the <tr> and <td> tags, it looked like a diamond because it was centered:
<center> <?php echo "<table border = 1>"; // loop for the pyramid for($i = 1; $i <= 10; $i += 2) { for($j = 1; $j <= $i; $j++) { echo "* "; } echo "<br />"; } // loop for the inverted pyramid, so it looks like a diamond for($i = 7; $i >= 1; $i -= 2) { for($j = 1; $j <= $i; $j++) { echo "* "; } echo "<br />"; } echo "</table>"; ?> </center>
Code with tags <tr> and <td> , for this you need "spaces" to make it look like aligned in the center:
<?php echo "<table border = 1>"; // loop for the pyramid echo "<tr>"; for($i = 1; $i <= 10; $i += 2) { echo "<tr>"; for($j = 1; $j <= $i; $j++) { echo "<td>* </td>"; } echo "</tr>"; } echo "</tr>"; // loop for the inverted pyramid, so it looks like a diamond for($i = 7; $i >= 1; $i -= 2) { echo "<tr>"; for($j = 1; $j <= $i; $j++) { echo "<td>* </td>"; } echo "<br />"; echo "</tr>"; } echo "</table>"; ?>
Please, help!
source share