Welcome Guest, Not a member yet? Register   Sign In
return multiple values from a function
#11

[eluser]Colin Williams[/eluser]
I think I would approach it in sophistry's manner. I would simply set properties of the model object to hold the data you want, and you can write getters for these properties if you want. Take note that this is how a lot of core libraries function. This is for the reason's sophistry already explained.

For example, your model could have a last_result and a last_result_count property that you could access, instead of returning anything from the method.
#12

[eluser]sophistry[/eluser]
this works for me...

not sure what the issue was for your set up. maybe calling the db in two separate controller calls? a redirect in between? some setting that resets the db connection after every single query?

The model:
Code:
<?php
class Tester_model extends Model {

    function Tester_model()
    {
        // Call the Model constructor
        parent::Model();
    }

    function get_one()
    {
        $this->db->select('SQL_CALC_FOUND_ROWS *');
        $this->db->limit(1);
        $q = $this->db->get('address');
        $r = $q->row();
        return $r;
    }
    
    function get_found_rows()
    {
        $this->db->select('FOUND_ROWS() as total');
        $this->db->limit(1);
        $q = $this->db->get('address');
        $r = $q->row();
        return $r->total;
    }
  
}
?>

The controller:
Code:
<?php

class Tester extends Controller {

    function Tester()
    {
        parent::Controller();    

    }


function test_found_rows()
    {
        $this->load->model('tester_model');

        $record = $this->tester_model->get_one();        
        print_r($record);
        
        $record = $this->tester_model->get_found_rows();        
        print_r($record);
    }
}

?>

Let us know if this works for you... you will be happier down the road if you design like this instead of using a single return array.




Theme © iAndrew 2016 - Forum software by © MyBB