Pagination please |
[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);
[eluser]geshan[/eluser]
You need to add limit in your query because thats how pagination works in CI.
[eluser]RaiNnTeaRs[/eluser]
can u send me ur code , so i can study it... thx.
[eluser]xwero[/eluser]
Code: $this->db->from(’tabel_news’);
[eluser]RaiNnTeaRs[/eluser]
Thanks a lot ^-^ ..So it doesnt always have to use models.
[eluser]xwero[/eluser]
You don't have to use models but it is recommended to keep your data retrieval and manipulation code centralized.
[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. ![]() Look at this: http://ellislab.com/forums/viewthread/76812/
[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
[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); 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. |
Welcome Guest, Not a member yet? Register Sign In |