0

I am trying to combine html and php to get a function.

<?php 
function display_text()
{
        $handle_text = '
        <div class="container">'.
        while($row=$stmt->fetch(PDO::FETCH_ASSOC))
        {
            extract($row); .'

                <div class="row">
                    <div class="col-2">
                    </div>
                    <div class="col-9">
                        '. echo $row['body']; .'
                    </div>
                </div> '.
        } .'
        </div>';

        return $handle_text ;
}
?>

However I get an error Parse error: syntax error, unexpected 'while' (T_WHILE) in C:\wamp64.
How could I manage it? Thank you in advance.

Kyv
  • 615
  • 6
  • 26
  • learn the basics of PHP, then you will figure out super easily – Alberto Sinigaglia Aug 18 '20 at 17:12
  • You can't just continue on the addition, you will need to add each part as you go along using `$handle_text .=...` – Nigel Ren Aug 18 '20 at 17:13
  • You're trying to concatenate *the loop itself* to the string. A loop doesn't return a value. Instead, concatenate to the string *within* the loop. So first define the container div string, then append each row within the loop, then after the loop concatenate the closing div. – David Aug 18 '20 at 17:13
  • You can't concatenate a string with a while statement. Consider storing the output of the loop in a variable then using it. – Wais Kamal Aug 18 '20 at 17:13
  • Ok thank you very much. – Kyv Aug 18 '20 at 17:16

0 Answers0