• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
nesting mysql results, need help passing the array to my view

#5
[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
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>&lt;?=$row->comment;?&gt;<p>
<h2>Reply</h2>
     &lt;?php foreach($reply as $rowReply) :?&gt;
     <p>&lt;?=$rowReply->reply;?&gt;<p>
     &lt;?php endforeach; ?&gt;
&lt;?php endforeach; ?&gt;

Can someone help me and let me know what i am doing wrong


Messages In This Thread
nesting mysql results, need help passing the array to my view - by El Forum - 08-17-2011, 03:06 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.