Welcome Guest, Not a member yet? Register   Sign In
Pagination please
#1

[eluser]RaiNnTeaRs[/eluser]
Hi..can someone help me ( again ) with paging ?
i dont get how it works...
I understand that we need controllers and view models to create something with Ci
my controller name is : dojang.php
and my view file is : news_view.php
index.php is located in www.localhost.com/ci2/index.php

in this news_view i Have 20 lines of rows and i would like to separate them into pages
1st page : 1..10
2nd page : 11..20
I've wrote this code on my controller file (dojang.php) and it didnt work, can someone help me solve this problem ? thanks a million lol.
$this->db->from('tabel_news');
$this->db->orderby("tanggal","asc");
$query = $this->db->get();
$data['query']=$query;

$config['base_url']='http://192.168.1.188/ci2/index.php/dojang/news_view';
$config['total_rows']='200';
$config['per_page']='10';
$config['uri_segment']='4';

$this->pagination->initialize($config);
echo $this->pagination->create_links();
//LOAD VIEW
$this->load->view('news_view',$data);
#2

[eluser]geshan[/eluser]
You need to add limit in your query because thats how pagination works in CI.
#3

[eluser]RaiNnTeaRs[/eluser]
can u send me ur code , so i can study it... thx.
#4

[eluser]RaiNnTeaRs[/eluser]
code plz ...
help help ... lol
#5

[eluser]xwero[/eluser]
Code:
$this->db->from(’tabel_news’);
$this->db->orderby("tanggal”,"asc");
if($this->uri->segment(4))
{
   $this->db->limit(10,$this->uri->segment(4));
}
$query = $this->db->get();
$data[’query’]=$query;
#6

[eluser]RaiNnTeaRs[/eluser]
Thanks a lot ^-^ ..So it doesnt always have to use models.
#7

[eluser]xwero[/eluser]
You don't have to use models but it is recommended to keep your data retrieval and manipulation code centralized.
#8

[eluser]taewoo[/eluser]
I recommend models b/c if you have a lot of code and are tired, looking for that "db->query" makes you dizzy. Big Grin

Look at this: http://ellislab.com/forums/viewthread/76812/
#9

[eluser]RaiNnTeaRs[/eluser]
hmmm i c, finally i managed to use the pagination class done, but 1 think ,thats confusing me , how to use a pagination class together with your own query.Like : myquery is :
$query = "SELECT hforum.*,count(*) as topics from hforum,dforum where dforum.topic_id=hforum.id group by hforum.id";

there are 20 rows as a result in that query, and i want to divide into 4 different section, how can i do that ? thanks
#10

[eluser]xwero[/eluser]
The pagination doesn't work that way because it would cause confusion. You can do this
Code:
$config['per_page'] = floor($total/4);
But that means if your total goes up you will have more items per page. Instead of 5 items you would have 10 if you have 40 rows.

It's best to have a consistent volume of items per page. It's not always the case because the last page can have 1 to the number of the per_page setting items but it's something everyone understands.




Theme © iAndrew 2016 - Forum software by © MyBB