Welcome Guest, Not a member yet? Register   Sign In
Hi Query per pagination problem.
#1

[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>&lt;?=anchor('articulos/'.$articulo->Url, $articulo->Title);?&gt;</dt>
              <dd class="pict"><img >Graphics; ?&gt;" alt="ultimas noticias" /></dd>
              <dd class="text"><p>&lt;?=character_limiter($articulo->Description, 550)?&gt;</p>
              <em>&lt;?=$articulo->Fecha;?&gt;</em>
              <span>&lt;?=$articulo->Comments;?&gt;</span>
              &lt;?=anchor('blog/'.$articulo->Url, 'read more', 'class="readmore"');?&gt;
              </dd>
&lt;?php endforeach; ?&gt;

I hope someone can help me
Thanks in advance


Messages In This Thread
Hi Query per pagination problem. - by El Forum - 11-18-2010, 01:07 PM
Hi Query per pagination problem. - by El Forum - 11-18-2010, 01:26 PM
Hi Query per pagination problem. - by El Forum - 11-18-2010, 01:46 PM
Hi Query per pagination problem. - by El Forum - 11-18-2010, 01:58 PM
Hi Query per pagination problem. - by El Forum - 11-18-2010, 02:09 PM
Hi Query per pagination problem. - by El Forum - 11-26-2010, 12:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB