Skip to content

PHP code snippet – How to write orderby in join query with where clause inigniter?

public function getLatestStatus($data, $userid)
	{
		$this->db->select('
				S.shipment_id,
				S.added_on,
				S.waybill_number AS waybill,
				s_status_logs.updated_on,
				s_status_logs.status_location,
				s_status_logs.px_statuscode,
				s_status.status_title,
				s_status_logs.status_description AS remark,
				transitpartner_name
			');
		$this->db->from('shipments as S');
		$this->db->join('users', 'users.user_id=S.user_id', 'left');
		$this->db->join('master_transit_partners as mtp', 'mtp.transitpartner_id=S.fulfilled_by', 'left');
		$this->db->join('shipments_status_logs as s_status_logs', 's_status_logs.shipment_id=S.shipment_id', 'left');
		$this->db->join('shipments_status as s_status', 's_status.status_id=s_status_logs.px_statuscode', 'left');
		$this->db->where('S.waybill_number', $data);
		$this->db->or_where('S.shipment_id', $data);
		$this->db->where('S.user_id', $userid);
		$this->db->limit(1, 1);
    $this->db->order_by('S.shipment_id', 'desc');
		$query = $this->db->get();
		return $query->result_array();
	}
See also  PHP code snippet - How to login laravel passport with postman?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.