how to write orderby in join query with where clause in codeigniter

Solutions on MaxInterview for how to write orderby in join query with where clause in codeigniter by the best coders in the world

showing results for - "how to write orderby in join query with where clause in codeigniter"
Till
12 May 2017
1public function getLatestStatus($data, $userid)
2	{
3		$this->db->select('
4				S.shipment_id,
5				S.added_on,
6				S.waybill_number AS waybill,
7				s_status_logs.updated_on,
8				s_status_logs.status_location,
9				s_status_logs.px_statuscode,
10				s_status.status_title,
11				s_status_logs.status_description AS remark,
12				transitpartner_name
13			');
14		$this->db->from('shipments as S');
15		$this->db->join('users', 'users.user_id=S.user_id', 'left');
16		$this->db->join('master_transit_partners as mtp', 'mtp.transitpartner_id=S.fulfilled_by', 'left');
17		$this->db->join('shipments_status_logs as s_status_logs', 's_status_logs.shipment_id=S.shipment_id', 'left');
18		$this->db->join('shipments_status as s_status', 's_status.status_id=s_status_logs.px_statuscode', 'left');
19		$this->db->where('S.waybill_number', $data);
20		$this->db->or_where('S.shipment_id', $data);
21		$this->db->where('S.user_id', $userid);
22		$this->db->limit(1, 1);
23    $this->db->order_by('S.shipment_id', 'desc');
24		$query = $this->db->get();
25		return $query->result_array();
26	}