php - Get ALL results from database with username -
how can keep checking posts php? have piece of code goes through , gets posts. when echo $row['post_message']; of messages. when set variable $post = $row['post_message'];, , <h2><?php echo $post;?></h2> 1 result. here's code
$stmt = $con->prepare("select post_message posts post_user = :username"); $stmt->bindvalue(':username', $username, pdo::param_str); $row = $stmt->fetchall(); $stmt->execute(); while($row = $stmt->fetch(pdo::fetch_assoc)){ $post = $row['post_message']; } so when echo i pie pie 2alex likes food, , when store in variable alex likes food. ideas?
your issue lies in while loop. keep overwriting $post variable. should be:
$posts = array(); while($row = $stmt->fetch(pdo::fetch_assoc)){ $posts[] = $row['post_message']; } which should return:
array ( [0] => pie pie 2, [1] => alex likes food ) this allows (as example):
foreach($posts $post) { echo 'the user posted: ' . $post . '<br />'; }
Comments
Post a Comment