2015-06-09 23 views
0

$data是包含从订单表中提取记录如何获取从订单表中的所有记录笨

$data=array('customer_id'=>$this->input->post('custId'),'paided'=>2); 
$this->db->select('*'); 
$this->db->from('orders'); 
$this->db->where($data); 
$this->db->get(); 
+0

其没” t返回所需的数据,我错了,请告诉我 –

+0

你需要的数据是什么,你的查询出了什么问题? – Saty

+0

我需要的数据是在订单表,我们通过客户id作为custId和paided = 2,哪些记录属于这种情况,他们都需要 –

回答

0

这是使用框架的加分,你不需要编写用户提交数据的数组这么多的代码,

$where = array('customer_id' => $this->input->post('custId'),'paided'=>2) 

$result = $this->db->get_where('orders', $where); 

和获取它们,使用$result->row()单记录检索。

如果你想所有的记录,使用$result->result()

这里是documentation link,如果你想了解更多。

+0

我需要整个记录在订单表,其中'customer_id'= $ this-> input-> post ( 'CUSTID');和'paided'= 2 –

+0

看到我编辑的答案 – Viral

0

简单使用

$custId = $_post['custId']; 

$query = $this->db->query("SELECT * FROM orders WHERE customer_id= '$custId' AND paided='2'"); 
$result = $query->result_array(); 
return $result;//result will be array 
2
$data = array(
    'customer_id'  =>  $this->input->post('custId')], 
    'paided'   =>  2 
); 

$this->db->select('*'); 
$this->db->from('orders'); 
$this->db->where($data); 

$this->db->get(); 
+0

虽然这个答案可能是正确和有用的,但是如果你包含一些解释并解释它如何帮助解决问题,那么这是首选。如果存在导致其停止工作并且用户需要了解其曾经工作的变化(可能不相关),这在未来变得特别有用。 –

1

你做得都好只需要把结果()如果你多行或行(),如果你得到一个行

$data=array('customer_id'=>$this->input->post('custId'),'paided'=>2); 
$this->db->select('*'); 
$this->db->from('orders'); 
$this->db->where($data); 
$result= $this->db->get()->result(); //added result() 
print_r($result); 
+0

感谢所有我的朋友:) –

2

试试这个:

public function function_name(){ 
$data = array (
    'customer_id' => $this->input->post('custId'), 
    'paided'  => 2 
); 

$this->db->select('*'); 
$this->db->from('ordere'); 
$this->db->where($data); 

$query = $this->db->get(); 
return $query->result_array(); 
} 
+0

你真的需要实现什么?你能解释更多,所以我们可以帮助你吗? – aizele

+0

感谢我的朋友#Abdulla :) –

+0

感谢我的朋友#aizele :) –

0

你应该需要什么Correc T和为什么

$data=array('customer_id'=>$this->input->post('custId'),'paided'=>2); 
$this->db->select('*'); // by defaul select all so no need to pass * 
$this->db->from('orders'); 
$this->db->where($data); 
$this->db->get(); // this will not return data this is just return object 

所以你的代码应该是

$data=array('customer_id'=>$this->input->post('custId'),'paided'=>2); 
$this->db->select(); // by defaul select all so no need to pass * 
$this->db->from('orders'); 
$this->db->where($data); 

$query = $this->db->get(); 
$data = $query->result_array(); 
// or You can 
$data= $this->db->get()->result_array(); 

这里result_array()回报纯数组,你也可以使用result() 这将返回对象的数组

相关问题