0

I keep on receiving this error message when running the PHP code below ::

"Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\informationdb\item.php on line 93"

I am trying to output dynamic PHP variables in a static html table using a foreach loop. By any chance, can anyone spot where the error lies?

My code is as follows::

<table>
<form action='', method="POST"> 

                            <?php 
                            foreach($libitem["libraries"] as $library) { 
                                foreach($libitem["libraryitemids"] as $libraryitemid) { 
                                    foreach($libitem["sectionnames"] as $sectionName) { 
                                        foreach($libitem["sectionnumbers"] as $sectionNumber) {
                                            echo "<tr><td id='radiocell'><input type='radio' name='libraryitemid' id='radio' value='" . $libraryitemid . "'></td><td>" . echo $library . "</td><td>" . echo $sectionName . "</td><td>" . echo $sectionNumber . "</td><td class='available'>Available</td></tr>";                                    
                                        } 
                                    } 
                                } 
                            } 

                            ?>


                        </table>
Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49
Robert Young
  • 523
  • 1
  • 8
  • 22
  • P.s. just in case anyone is wondering, line 93 is the line that the 'echo' statement is on :) – Robert Young Apr 20 '15 at 12:37
  • One echo is enough when concatenating. Also you may consider re-writing those foreaches into something less....performance loss-y. – Andrei Apr 20 '15 at 12:37

5 Answers5

3

When you are concatenating a string, you use dots, but no echo, also see the manual:

echo "<tr><td id='radiocell'><input type='radio' name='libraryitemid' id='radio' value='" . $libraryitemid . "'></td><td>"
    . echo $library . "</td><td>"
    . echo $sectionName . "</td><td>"
    . echo $sectionNumber . "</td><td class='available'>Available</td></tr>";  

should be:

echo "<tr><td id='radiocell'><input type='radio' name='libraryitemid' id='radio' value='" . $libraryitemid . "'></td><td>"
    . $library . "</td><td>"
    . $sectionName . "</td><td>"
    . $sectionNumber . "</td><td class='available'>Available</td></tr>";  
jeroen
  • 91,079
  • 21
  • 114
  • 132
1

Don't use echo here

 . echo $library . "</td><td>" . echo $sectionName . "</td><td>" . echo $sectionNumber . "

There is need only first echo. For concatenation isn't necessary.

Kristiyan
  • 1,655
  • 14
  • 17
0

Remove echo from inside the string.

For example, " . $libraryitemid . "'></td><td>" . echo $library . "</td><td>" . echo $sectionName . shoule be " . $libraryitemid . "'></td><td>" . $library . "</td><td>" . $sectionName . "<

Grim...
  • 16,518
  • 7
  • 45
  • 61
0

Try this:

echo "<tr><td id='radiocell'><input type='radio' name='libraryitemid' id='radio' value='" . $libraryitemid . "'></td><td>" . $library . "</td><td>" . $sectionName . "</td><td>" . $sectionNumber . "</td><td class='available'>Available</td></tr>";                                    
2kai
  • 603
  • 4
  • 13
0

you are using echo in the echo which is an error . remove this line .

echo "<tr><td id='radiocell'><input type='radio' name='libraryitemid' id='radio' value='" . $libraryitemid . "'></td><td>" . echo $library . "</td><td>" . echo $sectionName . "</td><td>" . echo $sectionNumber . "</td><td class='available'>Available</td></tr>";

you should use this

<table>
<form action='', method="POST"> 

                            <?php 
                            foreach($libitem["libraries"] as $library) { 
                                foreach($libitem["libraryitemids"] as $libraryitemid) { 
                                    foreach($libitem["sectionnames"] as $sectionName) { 
                                        foreach($libitem["sectionnumbers"] as $sectionNumber) {
                                            echo "<tr><td id='radiocell'><input type='radio' name='libraryitemid' id='radio' value='" . $libraryitemid . "'></td><td>" .  $library . "</td><td>" .  $sectionName . "</td><td>" . $sectionNumber . "</td><td class='available'>Available</td></tr>";                                    
                                        } 
                                    } 
                                } 
                            } 

                            ?>


                        </table>
Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68