How to avoid the repetation of date and voucher number? How to avoid the repetation of date and voucher number? codeigniter codeigniter

How to avoid the repetation of date and voucher number?


This Controller Code

  $this->db->select('*');    $this->db->distinct(    );    $this->db->where('Date >=',  $newDate);    $this->db->where('Date <=',  $newDate2);    $result = $this->db->get('journal')->result_array();             if($result){                $finalArray = array();                $checkArray = array();                foreach ($result as $key => $value) {                    if(in_array($value['Vno'], $checkArray)){                        $finalArray[$value['Vno']][] = $value;                    } else {                        $checkArray[] = $value['Vno'];                        $finalArray[$value['Vno']][] = $value;                    }                }                $data['query'] = $finalArray; 

My Answer Imageenter image description here


First, get unique Date and Vno from DB

$this->db->select('Date, Vno');$this->db->distinct();$query = $this->db->get('journal')->result();    

Now, use these to get all the records from DB

$unique_date = array(); $unique_vno = array();foreach($query as $row){    array_push($unique_vno, $row->Vno);    array_push($unique_date, $row->Date);   }$this->db->select('*');$this->db->where_in('Date',  $unique_date);$this->db->where_in('Vno',  $unique_vno);$query = $this->db->get('journal');    $data['PName']=$query->result_array();