希望使用json将单个codeigniter查询结果传递给我的控制器。
我的模特功能是:
function get_linked_loads_qty($q){
$sql = $this->db->query("
IF EXISTS(
select qtylinkedorders
from Linked_Order_Summary
join Linked_Order_lines
on Linked_Order_Summary.linkedorderid= Linked_Order_lines.linked_order_id
where load_number='$q'
)
begin
select qtylinkedorders
from Linked_Order_Summary
join Linked_Order_lines
on Linked_Order_Summary.linkedorderid= Linked_Order_lines.linked_order_id
where load_number='$q'
END
ELSE BEGIN
select 1 as qtylinkedorders
from customer_Order_lines
where CustomerOrderID='$q'
group by CustomerOrderID
END
");
$query = $this->db->get();
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row[qtylinkedorders])); //build an array
}
return $row_set;
}
}
我的控制器是:
function get_linked_loads_qty(){
$this->load->model('Sales_model');
if (isset($_POST['data'])){
$q = strtolower($_POST['data']);
$data = $this->Sales_model->get_linked_loads_qty($q);
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
}
sql在mssql中100%工作。 codeigniter错误是:
<p>Error Number: 42000</p><p>[Microsoft][SQL Server Native Client 11.0][SQL Server]Must specify table to select from.</p><p>SELECT *</p>
如上所述,查询在mssql中完美执行。
欢迎任何协助。感谢。
答案 0 :(得分:1)
我认为不需要$this->db->get()
,这是导致错误的原因。 $this->db->query("blah...")
将运行查询并返回结果。见CodeIgniter DB Query Docs