Get ALL results from database with username

前端 未结 1 1210
小鲜肉
小鲜肉 2021-01-24 12:32

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 th

相关标签:
1条回答
  • 2021-01-24 12:58

    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($posts as $post) {
        echo 'The user posted: ' . $post . '<br />';
    }
    
    0 讨论(0)
提交回复
热议问题