PHP PDO - Get Everything from table

Status
Not open for further replies.

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Hey everyone,

So for my latest project, I need to get everything from table and, show them in a modal.

My code atm:
PHP:
<?php 
        $getChangelog = $db->prepare('SELECT * FROM changelogs ORDER BY id DESC'); 
       $getChangelog->execute();
        $changelog = $getChangelog->fetchAll(); // testing purposes
     ?> 
// modal shit here 

<?php
 <?php while ($row = $getChangelog->fetch(PDO::FETCH_ASSOC))
{
print_r($row);
} ?>
and it returns nothing.
Any clues why?


Thanks.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,128
2,456
PHP:
<?php
$query = $db->prepare('SELECT * FROM changelogs ORDER BY id DESC'); 
$query->execute();

$result = $query->fetchAll();
?>

// Modal

<?php
foreach ($result as $row) {
    echo $row;
}
?>

You already did a fetchAll, which fills $result (or $changelog in your code) with an array with data. Just have to loop through it with foreach. The fetch() isn't needed.
 
Status
Not open for further replies.

Users who are viewing this thread

Top