使用php创建乘法表[关闭]

I'm trying to create multiplication table using php as follows:

<?php

$cols = 10;
$rows = 10;
?>

... lot of html code ...

<?php

echo "<table border=\"1\">";

        for ($r =0; $r < $rows; $r++){

            echo('<tr>');

            for ($c = 0; $c < $cols; $c++)
                echo( '<td>' .$c*$r.'</td></tr>');

        }

        echo("</table>");

?>

I probably miss something but can't figure out what is it.

Any advices would be appreciated, thanks!

try this:

you are closing tr tag for each column. you need to close tr tag after cloumn for loop.

echo "<table border=\"1\">";

        for ($r =0; $r < $rows; $r++){

            echo'<tr>';

            for ($c = 0; $c < $cols; $c++)
                echo '<td>' .$c*$r.'</td>';
           echo '</tr>'; // close tr tag here

        }

  echo"</table>";

Move the </tr> tag to outside the inner for loop:

echo "<table border=\"1\">";

for ($r =0; $r < $rows; $r++){

    echo('<tr>');

    for ($c = 0; $c < $cols; $c++)
        echo( '<td>' .$c*$r.'</td>');

    echo('</tr>');

}

echo("</table>");