[eluser]vinofilus[/eluser]
Sorry, that title doesn't even make sense to me. Here's what I'm trying to do
I have a table called Tasks (id, title, date, details),
and a table called Comments (id, task_id, date, details).
Each task is unique, and many Comments can refer to one task.
I'd like to show a table with the following columns:
Task Title | Task Details | Task Date | Number of Comments | Link to add comments
I can't figure out how to get the "Number of Comments" part to work.
The index function of my controller has:
$data['query'] = $this->db->get('Tasks');
$this->load->view('projects_view', $data);
and my projects_view has a foreach loop and link using code like:
<?php foreach($query->result() as $row): ?>
<tr><td><?=$row->title?></td><td><?=$row->details?></td><td><?=$row->date?></td>
<td>PROBLEM</td>
<td><?=anchor('projects/comments/'.$row->id, 'Comments');?></td>
</tr>
<?php endforeach; ?>
The comments()function in my controller shows all the comments related to a particular task just fine, with this:
$this->db->where('entry_id', $this->uri->segment(3));
$data['query'] = $this->db->get('Comments');
$this->load->view('comment_view', $data);
All of that works fine except for the PROBLEM cell on the Tasks where I want to show the
number of comments.
I can figure out the sql on my command line to show me the number of comments for each task_id using COUNT(Comments.task_id) and JOINing Comments.task_id = Task.id, but I can not figure out how to have the controller also do that sql work and pass it along to the view.
I might be thinking about this totally illogically. I welcome any feedback, solutions, re-direction, or further questions.
You can even make me start over.
This is more about learning how to do this than just getting it done, so I welcome your thoughts.
Many thanks.
Les...