PDO - Fetch Assoc in a 'while' loop
<p>I'm trying to echo a bit of html within a while loop. I'm getting my stuff with <a href="https://en.wikipedia.org/wiki/PHP#Development_and_community" rel="nofollow noreferrer">PDO</a> and PDO_ASSOC.</p>
<p>This is what I have:</p>
<pre><code>$stmt = $this-&gt;conn-&gt;prepare('SELECT * FROM books');
$stmt-&gt;execute();
while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC))
{
    $book_id = $row['id'];
    $book_title = $row['title'];
    $book_image = $row['image'];
    $book_amz = $row['amazon'];
    $book_desc = $row['description'];
    $book_rating = $row['rating'];
    $book_date = $row['date'];
    $book_author = $row['author'];
    $book_categorie = $row['categorie'];
    $text = &quot;ID: ' . $book_id . '&quot;;
 }
 return $text;
</code></pre>
<p>But it gives me only one row of the table. I even tried <a href="https://www.php.net/manual/en/pdostatement.fetchall.php" rel="nofollow noreferrer">fetchAll</a>, but it gives me nothing.</p>