bukon bukon - 1 year ago 79
PHP Question

How to add a PHP Variable into HTML code

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

$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?

Answer Source

You could use

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

See the documentation for more examples.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download