create table in php
In this article, we will see how to create a table in PHP with an example code. Indenting the code properly will increase the readability, understandability, and modifiability of the code. HTML tags can be used to create a table . <table> tag is used to create the table body and it has a collection of rows/columns. To create a table row, we need to create <tr> tag. We can use the echo statement to display the table. To create a table shell, we need to create <td> and inside it we gave some values.
Ex:
<?php
echo "<table border="1px" width = "200px">";
echo "<tr>";
echo "<td>1</td>";
echo "<td>2</td>";
echo "<td>3</td>";
echo "</tr>";
echo "<tr>";
echo "<td>1</td>";
echo "<td>2</td>";
echo "<td>3</td>";
echo "</tr>";
echo "</table>";
?>
Output:
- Here first, we have created <table> tag and the border is set to 1px width is set to 200px.
- Then we created two <tr> tags, it create two rows.
- Inside the <tr>, we have created three <td> tags and inside it we gave some values.
- See the output, the table is created successfully.