Why do I keep getting php error saying unexpected ')' in FOR statement?
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
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>";
}
Try using ;
instead of ,
to delimit the statements in the for loop expression. You can read more about php's for loop syntax here.
The for
syntax is:
for(intro; comp; inc) expr;
Notice the ;
instead of ,
inside the for
.
The statements inside the for-loop should be separated by semicolons, not commas. For example: for ($r=1; $r<10;$r++) { ... }
Don't for loops have the conditions separated by semicolons?
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.
精彩评论