ホームページ > php教程 > PHP源码 > codeigniter get分页教程

codeigniter get分页教程

PHP中文网
リリース: 2016-05-25 17:05:40
オリジナル
1117 人が閲覧しました

php代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

public function project_search(){

       $this->load->library('pagination');

       $this->load->model('depart_mdl');

       //获取搜索需要的信息

       $data = $this->get_project_data();

       $get_data = $this->input->get();

       $data = array_merge($data,$get_data);

       //get分页配置

       $name = $get_data['name'];

       $username = $get_data['username'];

       $budget = $get_data['budget'];

       $type = $get_data['type'];

       $posttime_start = $get_data['posttime_start'];

       $posttime_end = $get_data['posttime_end'];

       $purchase_type = $get_data['purchase_type'];

       $depart_code = $get_data['depart_code'];

       $project_status = $get_data['project_status'];

       $bidder_way = $get_data['bidder_way'];

       $suffix = "?name=$name&username=$username&budget=$budget&type=$type&posttime_start=$posttime_start&posttime_end=$posttime_end&purchase_type=$purchase_type&depart_code=$depart_code&project_status=$project_status&bidder_way=$bidder_way";

       $config['base_url'] = site_url('project/project_search').$suffix;

       $config['total_rows'] = $this->db->count_all($this->db->dbprefix('project'));

       $config['per_page'] = 10;

       $config['page_query_string'] = TRUE;

       //偏移量

       $config['query_string_segment'] = 'page';

       $config['uri_segment'] = 3;

       $this->pagination->initialize($config);

       $user = $this->user_mdl->get_user_by_salary_no($this->session->userdata('salary_no'));

       $this->db->from('ustc_project');

       $this->db->join('ustc_admins','ustc_admins.salary_no=ustc_project.salary_no');

       if($user->role!=1){

           $depart_code = explode(',',$user->grant_depart_code);

           $this->db->where_in('grant_depart_code',$depart_code);

           $this->db->or_where('ustc_project.salary_no =',$this->session->userdata('salary_no'));

       }

       if($name != ''){

           $this->db->like('name',$name);

       }

       if($username != ''){

           $this->db->like('username',$get_data['username']);

       }

       if($budget != ''){

           $this->db->like('budget',$get_data['budget']);

       }

       if($type != ''){

           $this->db->where('type',$get_data['type']);

       }

       if($depart_code != ''){

           $this->db->where('depart_code',$get_data['depart_code']);

       }

       if($purchase_type != ''){

           $this->db->where('purchase_type',$get_data['purchase_type']);

       }

       if($project_status != ''){

           $this->db->where('project_status',$get_data['project_status']);

       }

       if($bidder_way != ''){

           $this->db->where('bidder_way',$get_data['bidder_way']);

       }

       //时间

       if($posttime_start != ''){

           $this->db->where('posttime > ',strtotime($get_data['posttime_start']));

       }

       if($posttime_end != ''){

           $this->db->where(&#39;posttime < &#39;,strtotime($get_data[&#39;posttime_end&#39;]));

       }

       if(isset($get_data[&#39;page&#39;])){

           $page_from = $get_data[&#39;page&#39;];

       }else{

           $page_from = 0;

       }

       $this->db->order_by(&#39;posttime&#39;,&#39;desc&#39;);

       $projects = $this->db->limit($config[&#39;per_page&#39;],$page_from)->get()->result_array();   

        

       //处理

       for($i=0;$i<count($projects);$i++){

           $projects[$i][&#39;type&#39;] = $this->manage_info_mdl->get_value_by_id($projects[$i][&#39;type&#39;])->value;

           $projects[$i][&#39;purchase_type&#39;] = $this->manage_info_mdl->get_value_by_id($projects[$i][&#39;purchase_type&#39;])->value;

           $projects[$i][&#39;depart&#39;] = $this->depart_mdl->get_depart_by_code($projects[$i][&#39;depart_code&#39;])->name;

       }

       $data[&#39;projects&#39;] = $projects;

       //获取当前用户的角色

       $data[&#39;user_role&#39;] = $this->user_mdl->get_user_by_salary_no($this->session->userdata(&#39;salary_no&#39;))->role;   

       $this->_template(&#39;project_search&#39;,$data);

   }

ログイン後にコピー
関連ラベル:
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート