[eluser]mathew edison[/eluser]
Hey everyone,
First of let me tell you that I really enjoy using code igniter and that I really love the way it's formatted as it makes my life tons easier. I did however stumble into a problem which is more of the logical thinking nature than technical. I'm building my own portfolio for IT classes and I've added a blog. Now I have two Mysql tables one to hold the content of my posts and one for the comments. I related them by the field 'postid' in the comments table. Now on the same page I want to have a blog article and then number of comments posted on that article. How would I go at this? The following is what I have so far.
blog.php model:
Code:
function getposts()
{
$query = $this->db->get('blogarticles');
return $query;
}
welcome.php controller
Code:
$this->load->model('blog');
$data['queryblog'] = $this->blog->getposts();
$this->load->view('blog', $data);
blog.php view
Code:
<?php
if($queryblog->num_rows() > 0):
foreach ($queryblog->result() as $row):
?>
<div class="innerconttop"></div><div class="innercont">
<p><span class="newstitle"><?php echo $row->title; ?></span>
<br>Posted by <?php echo $row->user; ?> on <?php echo $row->date; ?><br><br>
<?php echo $row->body ?>
</div><div class="innercontbtm"><span class="comments">0 comments</span></div>
<?php
endforeach;
endif;
echo "</p>";
if($queryblog->num_rows() == 0):
?>
There are currently no articles posted. Our appologies</div>
<?php
endif;
?>
Any help on this matter would be highly appreciated and if you have any suggestions as to how I can improve this code please give them. I know the is a bad idea and I put that up as a temp. solution just untill I get some more time on my hands. Thanks in advance.
Sincerely
- Mathew