CodeIgniter分页结果问题

时间:2014-07-30 01:06:10

标签: php codeigniter pagination

我试图让这个工作但它失败了。

我有订单输出到仪表板上并希望拆分成活动订单&完成订单,我有标签可以切换,需要分页来单独处理它们。

控制器:

public function index($offset = 0) 
{

    $total_rows_active = $this->orders_m->where_in('`status`', array('pending', 'processing', 'processed', 'shipping'))->count_all();
    $total_rows_complete = $this->orders_m->where_in('`status`', array('complete'))->count_all();

    $this->data->pagination_active = create_pagination('admin/store/index', $total_rows_active);
    $this->data->pagination_complete = create_pagination('admin/store/index', $total_rows_complete);

    // Using this data, get the relevant results
    $this->data->items_active = $this->orders_m->limit($this->data->pagination_active['limit'], $this->data->pagination_active['offset'])->order_by('order_date','desc')->get_all();
    $this->data->items_complete = $this->orders_m->limit($this->data->pagination_complete['limit'], $this->data->pagination_complete['offset'])->order_by('order_date','desc')->get_all();

    // here we use MY_Model's get_all() method to fetch everything
    //$this->data->items = $this->orders_m->limit(Settings::get('records_per_page'))->offset($offset * Settings::get('records_per_page'))->order_by('order_date','desc')->get_all();
    //$this->data->pagination = create_pagination('admin/store/index', $this->orders_m->count_all());

    $this->data->check_stock_levels = $this->stock_levels_m->get_all();
    $this->data->stats = $this->stats_m->get_all();

    // Build the view with store/views/admin/items.php
    $this->template->title($this->module_details['name'])
        /*->append_metadata('<script type="text/javascript" src="https://www.google.com/jsapi"></script>')*/
        ->append_js('jquery/jquery.flot.js')
        ->append_js('module::stats.js')
        ->build('admin/dashboard', $this->data);
}

型号:

public function get_all() 
{
    $this->db->select('store_orders.*, inv.email as customer_email');
    $this->db->select('trans.amount as payment, trans.status as payment_status, history.status as status', FALSE);
    $this->db->select('CONCAT(inv.first_name, " ", inv.last_name) as customer_name', FALSE);
    $this->db->select('CONCAT(ship.zip, ", ", ship.city, ", ", ship.address1, " ", ship.address2) AS shipping_address', FALSE);
    $this->db->select('CONCAT(inv.zip, ", ", inv.city, ", ", inv.address1, " ", inv.address2) AS billing_address', FALSE);
    $this->db->join('(SELECT `status`, `amount`, `order_id` FROM `'.$this->db->dbprefix('store_transactions').'` ORDER BY `timestamp` DESC) trans', $this->db->dbprefix('store_orders').'.id =     trans.`order_id`', 'left', FALSE);
    $this->db->join('(SELECT `status`, `date_added`, `order_id` FROM `'.$this->db->dbprefix('store_order_history').'` ORDER BY `date_added` DESC) history', $this->db->    dbprefix('store_orders').'.id = history.`order_id`', 'left', FALSE);
    $this->db->join('store_addresses ship', 'store_orders.delivery_address_id = ship.id', 'left');
    $this->db->join('store_addresses inv', 'store_orders.billing_address_id = inv.id', 'left');
    $this->db->group_by('store_orders.id');
    return parent::get_all();
}

查看:

<div class="tabs">
    <ul class="tab-menu">
        <li><a href="#active_orders"><span>Active Orders</span></a></li>
        <li><a href="#complete_orders"><span>Completed Orders</span></a></li>
    </ul>
    <div id="active_orders"><?php print_r($items_active); ?><?php if(!empty($pagination_active['links'])): ?>
        <div class="paginate">
          <?php echo $pagination_active['links'];?>
        </div>
    <?php endif; ?>
    </div>

    <div id="complete_orders"><?php print_r($items_complete); ?><?php if(!empty($pagination_complete['links'])): ?>
        <div class="paginate">
            <?php echo $pagination_complete['links'];?>
        </div>
        <?php endif; ?>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

如果有两个或多个具有相同名称的列,在您的案例状态中,在不同的表格中,在您的where条件中,您必须更加精确。尝试在where_in条件中添加:table_namestatus,如下所示:

$total_rows_active = $this->orders_m->where_in('`'.$this->db->dbprefix('store_transactions').'`.`status`', array('pending', 'processing', 'processed', 'shipping'))->count_all();
$total_rows_complete = $this->orders_m->where_in('`'.$this->db->dbprefix('store_transactions').'`.`status`', array('complete'))->count_all();