how to fetch all records from order table in Codeigniter

1.1k views Asked by At

$data is an array which contain user post data for fetch record from orders table

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

There are 6 answers

1
viral On

This is the plus of using framework, you don't need to write that much of code,

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

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

and for fetching them, use $result->row() for single record retrieval.

If you want all records, use $result->result()

Here is documentation link, if you want to learn more.

0
Abdulla Nilam On

as simple use

$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
1
user123 On
$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
Mayank Tailor On

You have done all good just need to put result() if you get multiple row or row() if you get one row

$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
aiai On

try this :

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
Parth Chavda On

What You should need to be Correct And Why

$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

So Your Code Should be

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

here result_array() return pure array where you can also use result() this will return array of object