[eluser]clintonbeattie[/eluser]
Hi,
I have part of my blog app complete but having problems using the id of my blog post to display all related comments.
This is what I have...
My Model
Code:
function getComments($id){
$data = array();
//selects one row matching that ID from the products table
$options = array('post_id' => $id);
$Q = $this->db->getwhere('comments',$options,1);
if($Q->num_rows() > 0) {
$data = $Q->row_array();
}
$Q->free_result();
return $data;
}
My Controller
Code:
function post($id)
{
//this simply allows you to link to the post page by using the id
$post = $this->MBlog->getPost($id);
if (!count($post)){
redirect('welcome/index','refresh');
}
$data['post'] = $post;
$data['page_title'] = $post['post_title'];
$data['description'] = $post['description'];
$data['keywords'] = $post['keywords'];
$data['comments'] = $this->MBlog->getComments($id);
$data['main'] = 'post';
$this->load->vars($data);
$this->load->view('template');
}
My View
Code:
<?php
echo "<h4>".$post['post_title']."</h4>";
echo "<p>".date('d M Y', strtotime($post['post_date'])) ."</p>";
echo "<p>".$post['post_intro']."</p>";
echo "<p>".$post['post_text']."</p>";
?>
<h4>Comments</h4>
<?php
echo "<p>".date('d M Y', strtotime($comments['comments_date'])) ."</p>";
echo "<p>".$comments['comment_text']."</p>";
?>
I have tried to loop through the comments and list them, but it seems to output random dates like January 1970. I don't know where it got this from.
When I print_r($comments); all I get is one entry...
Any help much appreciated.
Thanks,
C