mayman212 Posted November 1, 2011 Share Posted November 1, 2011 <?php echo "<tableborder=1>"; echo "<table> \n"; echo " <tr>\n"; $a= 1; $b= 1; while ($a <= 9 && $b <= 10){ $calc = $a * $b; echo " <td>$calc</td>\n"; $a++; if ($a == 9){ echo " </tr>\n"; if ($b < 10) echo " </tr>\n"; $a = 1; $b++; } } echo "</table>"; ?> I am trying to do the multiplication tables but so far i can only manage to get this. it only shows the answers but i want it to show the tables along with the calculation, so for example: 1*2=2 2*2=4 etc. I want it to show on a repeating loop so it runs up to the 9 times tables. Any help on this? Quote Link to comment https://forums.phpfreaks.com/topic/250229-php-multiplication-tables/ Share on other sites More sharing options...
Nodral Posted November 1, 2011 Share Posted November 1, 2011 You could embed two For loops to acheive this <table> <?php for ($a=1; $a<=9; $a++){ echo "<tr>"; for ($b=1; $b<=9; $b++){ echo "<td>$a * $b = ".$a*$b."</td>"; } echo "</tr>"; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/250229-php-multiplication-tables/#findComment-1283940 Share on other sites More sharing options...
mayman212 Posted November 1, 2011 Author Share Posted November 1, 2011 Thanks for that. Quote Link to comment https://forums.phpfreaks.com/topic/250229-php-multiplication-tables/#findComment-1283952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.