0

So I am trying to make a multiplication table and have run into this issue :

<?php
$table = '';
if ($_POST) {
    $table .= '<table border="1">';
    for ($i = 0; $i < $_POST['qty_line']; $i++) {
        $table .= '<tr>';
        for ($j = 0; $j < $_POST['qty_column']; $j++) {
            $val = $i * $j;
           $table .= '<td width="50"> VARIABLE GOES HERE </td>';
        }
        $table .= '</tr>';
    }
    $table .= '</table>';
}
?>

Sorry if this is a very simple question but I can't find a solution after searching. Basically i want to insert the $val variable into where it says "VARIABLE GOES HERE" on that specific table data cell. How would I go about this?

1 Answer 1

2

You could use

$table .= '<td width="50">' . $val . '</td>';

See the documentation for more examples.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It works, I was doing that before although i wasn't closing the html and thus not concatenating it properly. Stupid mistake on my part..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.