MjM8082 Posted July 21, 2011 Share Posted July 21, 2011 I am trying to write a code that generates a grid table 5x5, 10X10, 12x12, whichever number the user types it will display a table. Each cell on the table will display a random number. Multiples of 3 will have the color red behind it and Multiples of 2 will have blue behind it. Everything was working great, but now I cant seem to get the table to work correctly. My code is duplicating the table and i'm not sure why. I think my for loops might not be closed correctly. If anyone can help I would appreciate it. Thanks. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Week 1 Lab</title> </head> <body> <?php if (isset($_POST['btn_submit'])) { $number_of_rows = $_POST['number_of_rows']; echo "<table cellpadding='5' cellspacing='5' border='1'"; echo "<tr>"; for($ii = 0; $ii < $number_of_rows; $ii++) { echo "<tr>"; for ($i=0; $i<$number_of_rows; $i++) { $my_no = mt_rand(1, 100); echo "<td>$my_no</td>"; if (($my_no%2==0)&&($my_no%3==0)) { $color="#FF00FF"; } else if ($my_no%2==0) { $color="#0000FF"; } else if ($my_no%3==0) { $color="#FF0000"; } else { $color ="#FFFFFF"; } echo "<td style=\"background: {$color};\">$my_no</td>"; } echo "</tr>"; } echo "</table>"; } ?> <form name="lab1" method="post" action="lab1.php"> <input type="textbox" name="number_of_rows" value="5" /> <input type="submit" name="btn_submit" value="Generate Grid" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/242581-php-code-help/ Share on other sites More sharing options...
teynon Posted July 21, 2011 Share Posted July 21, 2011 I just solved this via PM. Please mark this post as solved. Issue was echo "<td>$my_no</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/242581-php-code-help/#findComment-1245906 Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 bravo Quote Link to comment https://forums.phpfreaks.com/topic/242581-php-code-help/#findComment-1245910 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.