[eluser]MT206[/eluser]
Hi, I am new to CI and I am having trouble wrapping my head around some simple things. Right now all I am trying to do is just put the number of comments a blog post has under the post but for the life of me I cant figure out how to. I understand how you would do it with just PHP but obviously the point is to have CI make life easier so I am trying to use it. Any help would be much appreciated. Thanks
For people not familiar with the blog video tutorial here is the controller code:
Code:
function Blog(){
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
}
function index(){
$data['title'] = 'Mike\'s Blog';
$data['heading'] = 'Mike\'s Blog Heading';
$data['query'] = $this->db->get('entries');
$this->load->view('blog_view', $data);
}
function comments(){
$data['title'] = 'Mike\'s Blog';
$data['heading'] = 'Mike\'s Comment Heading';
$this->db->where('entry_id', $this->uri->segment(3));
$data['query'] = $this->db->get('comments');
$this->load->view('comment_view', $data);
}
function comment_insert(){
$this->db->insert('comments', $_POST);
redirect('blog/comments/' . $_POST['entry_id']);
}
}
?>
and the blog view code:
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading; ?></h1>
<?php foreach($query->result() as $row): ?>
<h3><?php echo $row->title; ?></h3>
<p><?php echo $row->body; ?></p>
<p><?php echo anchor('blog/comments/' . $row->id, 'Comments'); ?></p>
<hr>
<?php endforeach; ?>
</body>
</html>