need to create a multiplication table
Posted: Tue Oct 06, 2009 3:11 pm
the code looks right but it wont work. i know the problem has to be in the table somewhere...any suggestions will be GREATLY apperciated!!
Code: Select all
<?php
$rowcolors = array ("purple", "red", "yellow", "orange", "blue", "pink");
?>
<html>
<head>
<title>
</title>
</head>
<body>
Create a multiplication table<p>
<form method="get" action="<?php $_SERVER['php_self'];?> ">
Enter number of rows<br />
<input type="text" name="rownum" size="10" value="<?php echo $_GET['rownum'];?>"><p>
Enter number of columns<br />
<input type="text" name="colnum" size="10" value="<?php echo $_GET['colnum'];?>"><p>
Select a color<br />
<select name="color">
<?php
for ( $i = 0; $i < count( $rowcolors ); $i++ )
{
echo "<option value=\"" . $i . "\">" . $rowcolors[$i] . "</option>\n";
}
?>
<input type="hidden" name="do_php" value="true">
<p><input type="submit" value="Create Table">
</form>
<?php
if( isset( $_GET['do_php'] ) )
{
echo "<table width=\"50%\" border=\"3\">\n";
echo "<tr><td width='$cellwidth'> </td>";
for ( $j = 1; $j <= $_GET['colnum']; $j++ )
{
echo "<th>" .$j . "</th>\n";
}
for ($i = 1; $i <= $_GET['rownum']; $i++ )
{
echo "<tr>";
echo "<td>".$i."</td>\n";
}
echo "</tr>";
for ( $j = 1; $j <= $_GET['colnum']; $j++ )
{
echo "<td>".$i * $j."</td>\n";
}
}
echo "</table>";
?>
</body>
</html>