我们如何在网格上应用bootstrap分页表

时间:2015-12-14 04:31:00

标签: php codeigniter

我的观看代码

如何设置此代码以进行分页 在这段代码中帮助我

 <div class="property-grid">
              <div class="properties-table">
                <table id="example" class="table table-striped" cellspacing="0" width="100%">
                  <tbody>
                    <tr>
                      <ul class="grid-holder col-3">
                        <?php foreach ($r as $row) : ?>
                          <li class="grid-item type-rent">
                            <div class="property-block"> <a href="<?=base_url()?>controller/buy_and_sell/<?= $row->sub_id; ?>" class="property-featured-image"> <img src="<?=base_url()?>real/images/background-images/sub-category-images/<?= $row->sub_cat_images;?>" alt=""> <span class="images-count"><i class="fa fa-picture-o"></i> 2</span></a>
                              <div class="property-info">
                                <h4><a href="<?=base_url()?>controller/buy_and_sell/<?= $row->sub_id; ?>"><?= substr($row->sub_cat_name, 0, 24);?></a></h4>
                                <span class="location">NYC</span>
                                <div class="price"><strong>Items</strong>
                                  <span>
                                    <?php 
                                    $data = $this->model->get_product_count($row->sub_id);
                                    //echo array_shift($data);
                                    echo $data['count'];
                                    ?>
                                  </span>
                                </div>
                              </div>
                            </div>
                          </li>
                        <?php endforeach; ?>
                      </ul>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>

图片上传以获取帮助

for you help

bootstrap pegination表适用于我的网格

1 个答案:

答案 0 :(得分:1)

Codeigniter有自己的分页。请参阅以下链接以获取参考。

https://ellislab.com/codeigniter/user-guide/libraries/pagination.html

您也可以尝试此代码:

控制器上的

:在从模型中获取查询结果之前将其放入

//get the total rows first
    $totalrows = $this->your_model->total();

    $config = array();

    $config["base_url"] = base_url().'controller/grid/'; //I'm expecting that your method is 'grid'
    $config["total_rows"] = $totalrows; //total rows from your table
    $config["per_page"] = 6; //display atleast 6 per page
    $config["uri_segment"] = 3;

    $config['num_tag_open'] = "<li>";$config['num_tag_close'] = "</li>";
    $config['num_tag_open'] = "<li>";$config['num_tag_close'] = "</li>";
    $config['last_tag_open'] = "<li>";$config['last_tag_close'] = "</li>";
    $config['first_tag_open'] = "<li>"; $config['first_tag_close'] = "</li>";
    $config['next_tag_open'] = "<li>";$config['next_tag_close'] = "</li>";
    $config['prev_tag_open'] = "<li>";$config['prev_tag_close'] = "</li>";
    $config['cur_tag_open'] = "<li class='active'><a href='#'>";$config['cur_tag_close'] = "</a></li>";

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

$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;

//call your model here
$data['r']= $this->your_model->query_method($config["per_page"], $page); //result from your query for your products
$data["links"] = $this->pagination->create_links(); //pagination

在你的模特中:

function total(){
  $query = $this->db->get('table_name');
  return $query->num_rows();
}

function query_method($limit, $start){ //change the query_method to your original method name
    $this->db->limit($limit, $start); 
    $query = $this->db->get('table_name');

    return $query->results();

}

将此添加到您的视图:

            <?php
                if(isset($links)){ ?>
                    <div class="center">
                        <ul class="pagination pagination-sm">
                            <p><?php echo $links; ?></p>
                        </ul>
                    </div>
            <?php
                }
            ?>