pow(x,y) in php table

Hello,
I’m supposed to make a php-table where the left column shows a ist from 1-100 and the right column shows the left columns value x².

I’m stuck, my code looks like this, what am I doing wrong?

[code]<?php

$rows = 100;
$cols = 2;

echo “

”;

for($tr=1;$tr<=$rows;$tr++){

echo "<tr>";
    for($td=1;$td<=$cols;$td++){
           echo "<td align='left'>",pow($tr,2)."</td>";
    }
echo "</tr>";

}

echo “

”;

?>[/code]

Thanks in advance.

Something like this?

[php]<?php

$rows = range(1,100);
$cols = range(1,5);

?>

<?php for ($i = 2; $i < count($cols)+1; $i++) { ?> <?php } ?> <?php foreach ($rows as $row) { ?> <?php foreach ($cols as $col) { ?> <?php } ?> <?php } ?>
x^<?= $i ?>
<?= pow($row, $col) ?>
[/php]

Output:


The end result should look like this.
http://www.johanamtell.se/tabell.png

It does, just change $cols to range(1,2) and remove the headers (the first tr) and you’re set.

Oh I see now, couldn’t exec it before.

Thank you so much!

Sponsor our Newsletter | Privacy Policy | Terms of Service