Why do I keep getting php error with unexpected ")" in the FOR statement?

I am programming an HTML 10x10 table, each cell with a separate identifier and link. This went on for a long time with copy and paste and change, 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 says:

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

I took off stuf, I do not want you to see.

I am using Windows 7 with XAMPP version 1.7.3

+3
source share
6 answers

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

And please, unpin your code, this will greatly facilitate reading ...

- :

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>";
} 
+5

; ,, for. php .

+5

for:

for(intro; comp; inc) expr;

; , for.

+4

for , . : for ($ r = 1; $r < 10; $r ++) {...}

+2

, ?

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

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

.

PHP Manual .

+1

Source: https://habr.com/ru/post/1733276/


All Articles