good way to display db data the oop php way?

avp2k9

New Member
Im working on making a blog in oop php. Now Im trying to display the post entries in my db. I manage to output data from the created field but nothing else. Basically I have four fields in the post table in my db. I have created, author, title and body. With this code below I only manage to display created. Anyone got any clued to how I should proceed?! Do I need to create a new blog object for every field?! That seems so weird if so. Thanks! BTW the code is from my index.php...\[code\]<?phprequire_once('_settings.config.php'); global $db; $blog = new Blog("My Blog"); $posts = $blog->getPosts(); ?> <?php foreach ($posts as $post): ?> <li> <?php echo "<div>"; ?> <?php echo "<span class='footer'>Posted by: " . $post->author . "Created: " . $post->created . "</span>"; ?> <?php echo "</div>"; ?> <?php endforeach; ?> \[/code\]Here as requested is my getPosts function. It returns the $posts array.\[code\]public function getPosts() { $result = $this->db->query("SELECT * FROM posts"); $posts = array(); while($post = $result->fetch_assoc()) { array_push($posts, new BlogPost($post['id'], $post['created'], $post['author'], $post['title'], $post['body'])); } return $posts; } \[/code\]
 
Back
Top