Easily Create A Table In PHP

Here is a small PHP snippet to easily create a table in PHP.

First create the draw_table function.

$rows = 10; // amout of tr 
$cols = 10;// amjount of td 
function drawTable($rows, $cols){
echo "<table border='1'>"; 

for($tr=1;$tr<=$rows;$tr++){ 
     
    echo "<tr>"; 
        for($td=1;$td<=$cols;$td++){ 
               echo "<td align='center'>".$tr*$td."</td>"; 
        } 
    echo "</tr>"; 
} 

echo "</table>";
}

To draw the table on your page use the function we just created.

drawTable(30, 10);

This will create a table with 30 rows and 10 columns.

Advertise here

Comment