Welcome Guest, Not a member yet? Register   Sign In
how to have my query and pagination working?
#1

[eluser]Unknown[/eluser]
hi all, I have this in the view
Code:
&lt;?php $query = $this->db->query("SELECT * FROM noticies WHERE categoria<>'bre' ORDER BY data DESC");?&gt;
&lt;?php foreach($query->result() as $row):?&gt;

    <div class="quadrat &lt;?=$row->categoria?&gt;"><b>&lt;?php echo utf8_decode($row->titol)?&gt;</b>

    <p>&lt;?php echo utf8_decode($row->cos1)?&gt;</p>
    &lt;?=anchor('noticies/comentaris/'.$row->id, 'Comentaris');?&gt;

    </div>
&lt;?php endforeach; ?&gt;
<div class="quadrat">
    &lt;?php echo $this->pagination->create_links()?&gt;
</div>
and that in the controllers
Code:
$config['base_url'] = base_url()."index.php/noticies/index/";
        $config['total_rows'] = $this->db->count_all_results('noticies');
        $config['per_page'] = '4';
        $config['num_links'] = 4;
        $config['next_link'] = 'P&agrave;gina seg&uuml;ent &gt;';
        $config['prev_link'] = '&lt; P&agrave;gina anterior';
        $config['next_tag_open'] = '<div style="float:right;">';$config['next_tag_close'] = '</div>';
        $config['prev_tag_open'] = '<div style="float:left;">';$config['prev_tag_close'] = '&nbsp;</div>';
        $config['cur_tag_open'] = '<div style="float:left;"><b>';$config['cur_tag_close'] = '</b></div>';
        $config['num_tag_open'] = '<div style="float:left;">';$config['num_tag_close'] = '</div>';
        $this->pagination->initialize($config);
        $noticies['query'] = $this->db->get('noticies', $config['per_page'], (int)$this->uri->segment(3));

        $this->load->view('noticies/index', $noticies);
the point is: if I don't do the SQL line, all works fine, but if I do the special query, the HTML result shows all the database entrys (not 4 per_page), and the pagination (of course) doesn't work.

I know I'm doing something wrong, I'm new with CI, can you help me?
lots of thanks
#2

[eluser]Unknown[/eluser]
so what?
#3

[eluser]Murodese[/eluser]
Remove the "$query = " line in your view. Data should be passed to the view, not directly taken inside it.

You're generating the variable query in your controller and then overwriting it inside the view.




Theme © iAndrew 2016 - Forum software by © MyBB