CodeIgniter分页结果问题


CodeIgniter Pagination Result Issues

我正试图得到这个工作,但它失败了。

我有输出到仪表板的订单,并希望拆分为活动订单&完整的订单,我有选项卡来切换,需要分页来单独处理它们。

控制器:

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>

如果有两个或多个具有相同名称的列,在您的情况下,在不同的表中,在您的where条件中,您必须更精确。尝试添加:table_namestatus在你的where_in条件如下:

$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();