[英]Codeigniter Paging DB Results Issue
I am having an issue getting some paging code working with a query I am trying to run in one of my models. 我在使某些分页代码与要在我的模型之一中运行的查询一起工作时遇到问题。
I'll get to the issue in a moment 一会儿我会解决这个问题
public function current($page = 0){
if($_POST){
}else{
$this->db->start_cache();
$this->db->select('b.orderID, b.orderTracking, b.orderShipped, b.orderShippedOn, b.orderPaid, b.orderPaidOn,
(Select Top 1 c.payTranID From vwSelectOrderPayments c where c.orderID = b.orderID Order By c.payPosted Desc) as TranID');
$this->db->distinct();
$this->db->from('vwSelectOrders b');
$this->db->where('b.orderPaid', 1);
$this->db->where('b.orderPaidOn >', date('m/d/Y', strtotime('-300 days')));
$this->db->stop_cache();
$total_rows = $this->db->count_all_results();
$this->db->order_by('b.orderPaidOn', 'desc');
$this->db->limit(12, $page);
$qry = $this->db->get();
$rs = $qry->result_array();
$this->db->flush_cache();
$config['base_url'] = '/orders/current';
$config['per_page'] = 12;
$config['total_rows'] = $total_rows;
$config['num_links'] = 5;
$config['first_link'] = '<span class="fa fa-angle-double-left page_num"></span>';
$config['last_link'] = '<span class="fa fa-angle-double-right page_num"></span>';
$config['cur_tag_open'] = '<span class="page_num bold">';
$config['cur_tag_close'] = '</span>';
$config['next_link'] = '<span class="fa fa-angle-right page_num"></span>';
$config['prev_link'] = '<span class="fa fa-angle-left page_num"></span>';
$config['uri_segment'] = 2;
$config['num_tag_open'] = '<span class="page_num">';
$config['num_tag_close'] = '</span>';
$this->pagination->initialize($config);
$data['paging'] = $this->pagination->create_links();
}
$data['rs'] = $rs;
$data['current_page'] = $page;
$this->load->view('templates/header');
$this->load->view('pages/orders/current', $data);
$this->load->view('templates/footer');
}
Displays the 1st page without issue, however, upon clicking on of the paging links, I am presented with a CI Database Error: The multi-part identifier "b.orderID" could not be bound.
显示第一页没有问题,但是,单击页面链接时,出现CI数据库错误:
The multi-part identifier "b.orderID" could not be bound.
The query produced is: 产生的查询是:
SELECT b.orderID,b.orderTracking,b.orderShipped,b.orderShippedOn,b.orderPaid,b.orderPaidOn,
(Select Top 1 c.payTranID From vwSelectOrderPayments c where c.orderID = b.orderID Order By c.payPosted Desc) as TranID
FROM ( SELECT row_number() OVER (ORDER BY b.orderPaidOn desc) AS
CI_offset_row_number, b.orderID, b.orderTracking, b.orderShipped, b.orderShippedOn, b.orderPaid, b.orderPaidOn,
(Select Top 1 c.payTranID From vwSelectOrderPayments c where c.orderID = b.orderID Order By c.payPosted Desc) as TranID
FROM vwSelectOrders b
WHERE b.orderPaid = 1 AND b.orderPaidOn > '05/21/2013' ) AS A
WHERE A.CI_offset_row_number BETWEEN (13) AND (24)
With which I have attempted to run in MS SQL Manager, and was presented with: 我尝试使用它在MS SQL Manager中运行,并被呈现为:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "b.orderID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "b.orderTracking" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "b.orderShipped" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "b.orderShippedOn" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "b.orderPaid" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "b.orderPaidOn" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "b.orderID" could not be bound.
Now, I am using almost the exact same code in another model, and this issue does not occur. 现在,我在另一个模型中使用几乎完全相同的代码,并且不会发生此问题。 The difference between the 2 is the view I am querying.
2之间的区别是我正在查询的视图。
What can I do to fix this? 我该怎么做才能解决此问题?
You have to use fields with alias name A
. 您必须使用别名为
A
字段。
Instead of using b.orderID
, b.orderTracking
.... You should use as A.orderID
, A.orderTracking
. 而不是使用
b.orderID
, b.orderTracking
....您应该使用A.orderID
, A.orderTracking
。
change your code : 更改您的代码:
$this->db->select('A.orderID, A.orderTracking, A.orderShipped, A.orderShippedOn,A.orderPaid, A.orderPaidOn,
(Select Top 1 c.payTranID From vwSelectOrderPayments c where c.orderID = b.orderID Order By c.payPosted Desc) as TranID');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.