Hi. I'm pretty new to PHP, just trying to learn it myself. I found a tutorial online that was written by a professor for his PHP course, and it has helped me a bit. It also provides several exercises to work on.
One of these exercises is meant to teach creating dynamic tables with PHP. It is supposed to use FOR loops and IF statements to create a table with two rows. The top row shows the numbers 1 through 9, while the bottom row says "no" for every number <= 5, and "yes" for any number > 5.
I've changed the program around a bit. It's supposed to accept an integer from a form in a file "hello.php", and then pass the variable over to a file "tablemaker.php". Then it prints row one of the table as each iteration of the variable starting from 1. Row two starts off printing "no", then every five iterations it switches between "yes" and "no". It's a totally pointless program, I was using it just to practice some light programming, and I expected to not have any trouble with it, but I'm getting this stupid parse error and I want to know why. Anyway, here's the code.
Excerpt from hello.php:
<h2>Dynamic Table Creation:</h2>
<p style="width: 400;">Please enter a value below. The program will generate a 2-row table.
The top row will contain each iteration of the variable (beginning
at 1) until it hits the value entered. The bottom row will switch
between "Yes" and "No" every 5 iterations:</p>
<form action="tablemaker.php" method="get">
<p>Value: <input type="text" name="tvalue" /></p>
<p><input type="submit" value="Submit" /></p>
</form>
tablemaker.php:
<html>
<head>
<title>Table Test</title>
</head>
<body>
<table border="1" cellpadding="3">
<?php
$YN = "no"; // Initialize and declare Yes/No variable
for($i = 1; $i <= 2; $i++) //Begin FOR loop for creating table rows
{ ?>
<tr>
<?php if($i == 1) //If we are on the first table row
{
for($j = 1; $j <= $tvalue; $j++) //Then place $j in each box
{ ?>
<td style="align: center">
<?php echo $j; ?>
</td>
<?php }
} else {
for($j = 1; $j <= $tvalue; $j++) //otherwise, for each $j,
{
if($j%5 == 0) //if $j is divisible by 5
{
if($YN == "no") //change $YN to its opposite
$YN = "yes";
else
$YN = "no";
} ?>
<td style="align: center">
<?php echo $YN; ?>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</body>
</html>
I've also tried using $_GET['tvalue'] in the FOR loops instead of just $tvalue, and I still get the same exact error:
Parse error: parse error in /home/ziv/public_html/PHPTesting/tablemaker.php on line 39
Any ideas?