tags:

views:

75

answers:

6

I am programming an HTML 10x10 table, Each cell with a separate ID and link. It was taking way to long with copying and pasting and changing so I decided to use PHP, using the FOR command which I am not very familiar with.

I am using this code:

<table>
<?php 
for ($r=1, $r<10,$r++) {
;echo "<TR>";
for ($d=1, $d<10,$d++) {
echo "<TR id='d" . $d . "r" . $r . "'><a href='javascript: void(0)' onclick='shoot(" . $d . "," . $r . ")'>SHOOT!</a>";
}
echo "<TD>";
} 
?>
</table>

PHP is saying:

Parse error: syntax error, unexpected ')', expecting ';' in C:\xampp\htdocs\****\*****\index.php on line 16

i starred out the stuf I do not want you to see.

I am using Windows 7 with XAMPP version 1.7.3

+5  A: 

Try using ; instead of , to delimit the statements in the for loop expression. You can read more about php's for loop syntax here.

fbrereto
+1  A: 

Don't for loops have the conditions separated by semicolons?

John at CashCommons
+4  A: 

The for syntax is:

for(intro; comp; inc) expr;

Notice the ; instead of , inside the for.

Blindy
+5  A: 

Use a semicolon (;) in your for loop (instead of a comma).

And please indent your code, it makes it a lot easier to read...

Something like this:

for ($r=1; $r<10; $r++) {
    echo "<TR>";
    for ($d=1; $d<10; $d++) {
        echo "<TR id='d".$d."r".$r."'><a href='javascript: void(0)' onclick='"
             ."shoot(".$d.",".$r.")'>SHOOT!</a>";
    }
    echo "<TD>";
} 
ChristopheD
+2  A: 

The statements inside the for-loop should be separated by semicolons, not commas. For example: for ($r=1; $r<10;$r++) { ... }

cutterex
+1  A: 
for ($r=1, $r<10,$r++)

should be

for ($r=1; $r<10; $r++)

Your for statements are using commas instead of semi-colons.

The PHP Manual can be a big help.

ssakl