Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [codeigniter] Pagination - sortowanie
Forum PHP.pl > Forum > PHP > Frameworki
tabbi
Witam,

mam problem otóż wykorzystuję bibilioteke standardową paginacji z CI, wszystko działa super jednak np. gdy już na 5,6 stronie sortuje sobie dane np. chce tylko mieć pliki z licencji freeware to jest pusto chodź na stronie 5 istnieje taki plik.

  1. $this->load->model('File_model'); // Ładowanie modelu plików
  2. $config['base_url'] = base_url() . 'index.php/cat/lista/'.$this->uri->segment(3);
  3. $config['total_rows'] = $this->File_model->count_files($id);
  4. $config['per_page'] = 10;
  5. $config['num_links'] = 5;
  6. $config['first_link'] = 'Start';
  7. $config['last_link'] = 'Koniec';
  8. $config['full_tag_open'] = '<ul id="table-pagination">';
  9. $config['full_tag_close'] = '</ul>';
  10. $config['cur_tag_open'] = '<li>';
  11. $config['cur_tag_close'] = '</li>';
  12. //$config['suffix'] = '.html'; //do tagów w pagination
  13. $config['uri_segment'] = 4;
  14.  
  15. $license = $this->sort();
  16. $this->pagination->initialize($config);
  17. $file_list = $this->File_model->get_file_list($license,$id,$config['per_page'], (int)$this->uri->segment(4));
  18.  
  19. /**
  20.   * Sortowanie z formularza z widoku: cat_list.php
  21.   * @return string - lista licencji
  22.   */
  23. private function sort()
  24. {
  25. if( $this->input->post('license_type') )
  26. {
  27. $select_license = $this->input->post('license_type');
  28. switch($select_license) {
  29. case 'free':
  30. $wlicense = '1,2,3';
  31. break;
  32. case 'paid':
  33. $wlicense = '4,5';
  34. break;
  35. case 'all':
  36. default:
  37. $wlicense = '1,2,3,4,5,6';
  38. break;
  39. }
  40. }
  41. else
  42. {
  43. $wlicense = '1,2,3,4,5,6';
  44. }
  45. return $wlicense;
  46. }


MODEL:
  1. function get_file_list($license,$cat, $num="", $offset="")
  2. {
  3. $query = $this->db->query("SELECT licenses.name as nlicense, files.name as name, files.system_link as system_link, files.downloads as downloads, files.grade as grade, files.description as description, files.language as language, files.recomend as recomend, files.id as id, files.type as type FROM files LEFT JOIN licenses ON files.license = licenses.id WHERE files.cat IN ({$cat}) AND files.license IN ({$license}) ORDER BY files.name ASC LIMIT {$offset},{$num}");
  4. return $query->result_array();
  5. }
  6.  
  7. /**
  8.   * Zwraca liczbe newsów
  9.   * @return <int> liczbe newsow
  10.   */
  11. function count_files($cat)
  12. {
  13. $query = $this->db->query("SELECT * FROM files WHERE cat IN ($cat)");
  14. return $query->num_rows;
  15. }



Nie wiem co jest nie tak ehh ktoś ma jakąś wskazówke
adbacz
Cytat
gdy już na 5,6 stronie sortuje sobie dane

Jak odbywa się to sortowanie? Po pobraniu z DB wyników czy najpierw ustalasz jakie licencje a później pobierasz z bazy?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.