need help getting css to work with php variables
Posted: Sat Oct 10, 2009 9:08 pm
the object of my program is to make a multiplication table by getting user input for number of rows, columns and the color you want the background of everyother row to be. I FINALLY got the table to display correctly now my only trouble is the css. i've tried it every which way i can think of...i've googled throughout the night looking for answers if anyone could help me it would be greatly appreciated. if you dont understand my problem please just ask me to clerify because i'm not sure if i'm being clear enough.
Code: Select all
<html>
<head>
<title>
</title>
<script type="text/javascript">
function checkForm()
{
if( isNaN(document.multable.rownum.value) )
{
alert ("Sorry row number is not a number");
return false;
}
if( isNaN(document.multable.colnum.value) )
{
alert ("Sorry column number is not a number");
return false;
}
return true;
}
</script>
<?php
$rowcolors = array ("purple", "red", "yellow", "orange", "blue", "pink");
?>
</head>
<body>
Create a multiplication table<p>
<form name="multable" onSubmit="return checkForm()"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=\"" . $_GET['color'] . "\">" . $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> </td>";
if ( $i%2 == 0 )
{
echo "<div style=\"background:". $_GET['color'] . ";\">\n";
}
for( $i=1; $i<=$_GET['colnum']; $i++)
{
echo"<td>".$i."</td>\n";
}
echo"</tr>\n";
for( $j=1; $j<=$_GET['rownum']; $j++)
{
echo"<tr>";
echo"<td>".$j."</td>\n";
for( $k=1; $k<=$_GET['colnum']; $k++)
{
echo"<td>".$j*$k."</td>\n";
}
}
echo"</tr>\n";
echo"</div>\n";
}
echo"</table>\n";
?>
</body>
</html>