Skip to content Skip to sidebar Skip to footer

Get All Results From Database With Username

How can I keep checking for posts with PHP? I have a piece of code that goes through and gets all the posts. When I do echo $row['post_message']; I get all of the messages. When I

Solution 1:

Your issue lies in your while loop. You keep overwriting the $post variable. It should be:

$posts = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    $posts[] =  $row['post_message'];
}

Which should return:

Array (
    [0] => I like pie I like pie 2,
    [1] => alex likes food
)

This allows you to do something like this (as an example):

foreach($postsas$post) {
    echo'The user posted: ' . $post . '<br />';
}

Post a Comment for "Get All Results From Database With Username"