08-17-2011, 03:06 PM
[eluser]Miguel Diaz[/eluser]
One question I am trying to do the same thing but I am still new at this. I was trying to use my database model with this but it do not work. Can some one help me please
This is my model
and my controller
View
Can someone help me and let me know what i am doing wrong
One question I am trying to do the same thing but I am still new at this. I was trying to use my database model with this but it do not work. Can some one help me please
This is my model
Code:
function getReply()
{
$data = array();
$q = $this->db->query("select * from replies");
if($q->num_rows() > 0) {
foreach($q->result() as $row){
$data[] = $row;
}
$q->free_result();
}
return $data;
}
and my controller
Code:
$comments = $this->data_model->getComments($commentID);
// No longer need the if, since we know it's an array.
foreach ($comments as &$comment)
{
$comment['reply'] = $this->data_model->getReply($comment->commentID);
}
$op['comments'] = $comments;
$this->layouts->view('articulos-template', $op);
View
Code:
<?php foreach($comments as $row) :?>
<p><?=$row->comment;?><p>
<h2>Reply</h2>
<?php foreach($reply as $rowReply) :?>
<p><?=$rowReply->reply;?><p>
<?php endforeach; ?>
<?php endforeach; ?>
Can someone help me and let me know what i am doing wrong