簡體   English   中英

Codeigniter中的分頁(不能每頁顯示行數)

[英]Pagination in Codeigniter(Cannot show row per page)

在Codeigniter中進行分頁時遇到了一些問題。

它可以顯示表格下方的分頁鏈接

但它不能在每個頁面中每頁顯示5行,它顯示了每個頁面中從數據庫中檢索的總行數。

例如,我想要的是我有15行數據,每頁顯示5行數據。

希望有人能給我一些建議。 謝謝。

模型

public function record_count() {
        return $this->db->count_all("order");
    }

    public function fetch_order($limit, $start) {
        $this->db->limit($limit, $start);
        $query = $this->db->get("order");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

控制器和視圖

        $branchCode = "";
        if(!$this->session->userdata('branchcode')){ 
            $branchCode ="ABC";

            //if branchCode == ABC, show all orders from database
            $output = '';
            $pgcode = '';
            $this->load->model('order');
            if($this->input->post('code')){
                $code = $this->input->post('code');
            }

            $config = array();
            $config["base_url"] = base_url() . "index.php/Ordering/OrderListIndex/";
            $config["total_rows"] = $this->order->record_count();
            $config["per_page"] = 5;
            $config["num_links"] = 10;
            $config["uri_segment"] = 3;

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

            $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $links["results"] = $this->order->fetch_order($config["per_page"], $page);
            $links["links"] = $this->pagination->create_links();

            $data = $this->order->SearchCusOrder($code);
            //var_dump($data);          
                    $output .= '
                            <table class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>Order ID</th>
                                        <th width="250px">Name</th>
                                        <th>Date</th>
                                        <th>Pay Option</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                    ';
                    if($data->num_rows() > 0){
                        foreach($data->result() as $row){
                            if($row->status == 'Placed'){
                                $output.= '
                                        <tbody>
                                            <tr>
                                                <td>'.$row->id.'</td>
                                                <td>'.$row->cust_name.'</td>
                                                <td>'.$row->order_date.'</td>
                                                <td>'.$row->options.'</td>
                                                <td>'.$row->status.'</td>
                                                <td>
                                                    <a class="btn btn-warning" href="EditOrderPage/'.$row->id.'">Edit</a>
                                                    <a class="btn btn-success" href="GenerateInvoice/'.$row->id.'">Print Invoice</a>
                                                </td>
                                            </tr>
                                ';
                            }
                        }

                    }

            $output .= '
            </table>
            <ul class="pagination">
            <li class="page-item">'.$links["links"].'</li>
            </ul>
            ';
            echo $output;

        }

您必須將HTML添加到下面創建的輸出代碼並傳遞每頁總計值。

Codeigniter默認情況下不顯示每頁顯示的行數,如數據表。

您必須添加自定義HTML。

<span>Rows per pages 5 </span>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM