Reputation: 462
I am new to OOP in PHP and I am having some trouble with displaying results the way I would like. My query does gather all the results, The problem is that when trying to add a <br />
tag for formatting. I am getting my results, then some break tags then results and a different number of break tags and so on. I would expect from the way I coded it every result should have a <br />
after it but there is a different amount of <br />
tags after each one. Any advice would be helpful. Here is my code:
public function getForumActivity(){
$user = $this->uid;
$pdo = $this->db;
$stmt = $pdo->prepare("SELECT title FROM board WHERE user=:user");
$stmt->bindValue(':user',$user,PDO::PARAM_STR);
try{
$title = "";
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$title .= $row['title']."<br />";
}
return $title;
}
catch(PDOException $e){
echo $e->getMessage();
}
}
Upvotes: 0
Views: 83
Reputation: 1849
I assume that some of your rows in your database have null title value;
Upvotes: 3