How to reset / clear the order between two consecutive requests in CodeIgniter?

I am trying to invoke 2 consecutive requests in CodeIgniter, the first of which has an order-by clause. The problem is that CodeIgniter is trying to use the order-by clause for the second request and throw an error.

The code looks something like this:

 ...
 $sql = $this->db->get_where('expenses',array('category_id' => $category_id));
 $this->db->order_by("date", "asc");
 $data = $sql->result_array();

 foreach($data as $expense_rec)
 {
     $expense_id = $data['expense_id'];
     $sql2 = $this->db->get_where('expense_details',array('expense_id' => $expense_id));
     $detail_rec = $sql2->result_array();
 }
 ...

For the second request, the script throws the following error:

Unknown column 'date' in 'order clause'

SELECT * FROM (`expense_details`) WHERE `expense_id` = '4' ORDER BY `date` asc

Is there a way that I can reset to execute an order before calling the second request?

I am using CodeIgniter 1.7

PS I know that I can join two requests in one, but I'm curious to find out if there is a way for the above code to work in CodeIgniter.

+3
source share
3 answers

Running a request is what resets it.

order_by() , , .

...

$sql = $this->db->get_where('expenses',array('category_id' => $category_id));
$this->db->order_by("date", "asc");
$data = $sql->result_array();

...

$this->db->order_by("date", "asc");
$sql = $this->db->get_where('expenses',array('category_id' => $category_id));
$data = $sql->result_array();
+8

$this->db->_reset_select(), .

+2

. . , - . , Active Record, , .

, DB . , , . :

$new_db = $this->db;
$new_db->where('user_status', 1);

and etc.

+2
source

All Articles