[eluser]Miguel Diaz[/eluser]
Hi I am new working with databases and I am trying to make a blog and use the pagination library, If i use the get property works perfect but like I want to count the comments of each article when I change this to select doesnt work can someone help me please.
This is my controller
Code:
class Blog extends Controller {
function blog()
{
parent::Controller();
$this->load->model('data_model');
}
function index()
{
$this->load->library('pagination');
$config['base_url'] = base_url().'blog/index/';
$config['total_rows'] = $this->db->count_all('articles');
$config['per_page'] = 2;
$this->pagination->initialize($config);
$op['pagination_links'] = $this->pagination->create_links();
$tags = $this->uri->segment(1);
$op['tags'] = $this->data_model->cargarTags($tags);
$op['blog'] = $this->db->query("select f.entry_id as 'entry',
a.title as 'Title',
a.url as 'Url',
a.description as 'Description',
a.date as 'Fecha',
a.graphics as 'Graphics',
count(entry_id) as Comments
from articles a left join
forocomments f
on a.url=f.entry_id
group by idArticles
desc limit 3", $config['per_page'], $this->uri->segment(3));
//This work perfect but i need to count my forocomments
//$this->db->order_by('idArticles', 'DESC');
//$op['blog'] = $this->db->get('articles', $config['per_page'], $this->uri->segment(3));
//tags de scrypt extra por pagina//
$op['js']= '';
//Menu home este es diferente al contenido de la interior//
$op['nav'] = $this->data_model->cargarNavInteriores();
// Vista de Template
$op['content'] = 'blog-index';
$this->load->view('includes/template-content', $op);
}
}
and this is my view where or my articles are display.
Code:
<? foreach($blog->result() as $articulo) : ?>
<dt><?=anchor('articulos/'.$articulo->Url, $articulo->Title);?></dt>
<dd class="pict"><img >Graphics; ?>" alt="ultimas noticias" /></dd>
<dd class="text"><p><?=character_limiter($articulo->Description, 550)?></p>
<em><?=$articulo->Fecha;?></em>
<span><?=$articulo->Comments;?></span>
<?=anchor('blog/'.$articulo->Url, 'read more', 'class="readmore"');?>
</dd>
<?php endforeach; ?>
I hope someone can help me
Thanks in advance