[eluser]MT206[/eluser]
I have still not been able to get this to display the proper count. I might be misunderstanding what was shown in the above post but I do not think so.
From the code examples given above I do not understand why I would be changing the 'query' to 'comments' as that seems arbitrary and when I do I get the error: undefined variable comments which makes sense since there is no 'comments' variable in the index function to pass to the view. For more information the comment view looks like this:
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading; ?></h1>
<?php if ($query->num_rows() > 0): ?>
<?php foreach($query->result() as $row): ?>
<p><?php echo $row->author; ?></p>
<p><?php echo $row->body; ?></p>
<hr>
<?php endforeach; ?>
<?php endif; ?>
<?php echo form_open('blog/comment_insert'); ?>
<?php echo form_hidden('entry_id', $this->uri->segment(3)); ?>
Comment:
<p><textarea name="body" rows="10"></textarea></p>
Author:
<p><input type="text" name="author" /></p>
<p><input type="submit" value="Submit Comment" /></p>
</form>
<p><?php echo anchor('blog', 'Back to Blog'); ?></p>
</body>
</html>
And the Database setup is:
entries
id, title, body
comments
id, entry_id, author, body
Would I need another table that contains both entry_id and comment_id? I do not see how I could use data from both tables without manually writing an SQL query involving a JOIN or actually having a column for comment count which seems clunky.