[eluser]Unknown[/eluser]
I'm having some problems outputting a COUNT from SQL... My SQL query is as follows:
Code:
$this->db->select('entry_slug,entry_title,entry_body,entry_published,user_name,user_showname,COUNT(comment_id)');
$this->db->from('blog_entries');
$this->db->join('user_accounts','user_accounts.user_id=blog_entries.user_id','inner');
$this->db->join('blog_comments','blog_comments.entry_id=blog_entries.entry_id','left');
$this->db->group_by('blog_entries.entry_id');
My template looks like so:
Code:
<?= file_get_contents($_SERVER['DOCUMENT_ROOT'] .'header.html'); ?>
<? foreach($Entries->result() as $Entry): ?>
<?
$Date = mdate('%Y/%m/%d',mysql_to_unix($Entry->entry_published));
$Slug = addslashes(quotemeta($Entry->entry_slug));
$URLSlug = 'blog/'. $Date .'/'. $Slug;
if($Entry->user_showname != null) {
$Author = $Entry->user_showname;
} else {
$Author = $Entry->user_name;
}
?>
<h1><?= anchor($URLSlug,$Entry->entry_title); ?></h1>
<p class="MetaInformation">
<strong>
Published on <?= $Entry->entry_published; ?> by
<?= anchor('profile/'. $Entry->user_name,$Author); ?>
</strong>
</p>
<?= nl2br($Entry->entry_body); ?>
<p class="MetaInformation TxtRight">
<?= anchor($URLSlug .'/comments',$Entry->comment_id .' Comment(s)'); ?>
</p>
<? endforeach; ?>
<?= file_get_contents($_SERVER['DOCUMENT_ROOT'] .'footer.html'); ?>
Everything else outputs just fine, but I can't figure out how to print the COUNT result in my views template.
Any ideas?
Edit: Solved it with the slight addition 'AS comment_id' in the SQL, after COUNT(comment_id)