1次查询并从数组Codeigniter获取数据

I'm having problem optimizing my query.

My first query was I put the function model inside the loop and it takes time to load. So here's what I did

//// Controller

$drreturn = $this->getDRReturnAmount($date1);
$return_amount[] = $drreturn->return_amount;
$idno[] = $drreturn->idno;

// Model

public function getDRReturnAmount($date1){
 $sql = "SELECT *, IFNULL(SUM(totalamt), 0) as return_amount FROM 
 8_drreturnsummary WHERE trandate >= ?";
 $data = array($date1);
 $query = $this->db->query($sql, $data)->row();

 return $query;

  }

Since I put all the data in an array, is there a way to get specific data from an array? For example, I want to get the query of

SELECT *, IFNULL(SUM(totalamt), 0) as return_amount FROM 
 8_drreturnsummary WHERE idno = 0500

is that possible?