No, no, no.
First of all, you don't write a query inside a view page of CodeIgniter.
You must do it in Model, that's why CI is MVC framework.
Second, you can utilised database View. If you are using MySQL, you can create a View like:
CREATE VIEW last_card_id AS
select *
from registration_status
Third, you can use aggregate function in the first place without using sub-query, so the View will already contain the maximum registration_card_id based on registration_id. So we edit the View above:
CREATE VIEW last_card_id AS
selet max(registration_card_id) as 'max_id'
from registration_status
group by registration_id
then in your model file you can call the model:
public function get_max_card_id($registration_id){
$this->db->where('registration_id',$registration_id);
return $this->db->get('last_card_id')->row_array();
}
then in your controller:
public function max_card(){
$data['registration'] = $this->registration_model->get_max_card_id($registration_id);
$this->load->view('view_page',$data);
}
in view file:
<?php echo $registration['max_id'];?>