Welcome Guest, Not a member yet? Register   Sign In
problem with multiple query but different libraries used
#1

[eluser]extra_rice[/eluser]
i have a controller that loads several libraries... and from those libraries i call 1 query each... the problem is that the filters that i use in getting the list from 1 library is getting added to the filters i use for the next library and even to the next list method in the same library...

my controller:
Code:
class XHome extends Controller {

    function XHome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->library('services');
        $this->load->library('organizations');
        $this->load->library('rankings');
        $this->load->library('articles');

        //display services
        $data['services'] = $this->services->getList(array('status'=>ACTIVE_STATUS));

        //display articles
        $data['articles'] = $this->articles->getList(array('status'=>ACTIVE_STATUS), 10);
        
        //display faved organizations if logged-in
        if ( $this->session->userdata('logged_in') )
        {
            $data['favorites'] = $this->organizations->getFavorites( $this->session->userdata('user_id') );
        }

        //display user ranking
        $data['userRanking'] = $this->rankings->getUserList(array('MONTH(orders.system_receive_date)'=>10),10);

        //display organization ranking
        $data['organizationRanking'] = $this->rankings->getOrganizationList(array('MONTH(orders.system_receive_date)'=>9),10);
        
        $this->load->view('xhome', $data);        
    }
}

my Services library:
Code:
class Services {

    var $id = 0;
    var $name = '';
    var $table = 'services';

    function Services()
    {
        $this->obj =& get_instance();
    }
    
    function getList($where, $limit=10, $offset=0, $orderByField='id', $orderByDirection='asc')
    {
        $this->obj->db->where($where);
        $this->obj->db->order_by($orderByField,$orderByDirection);
        $query = $this->obj->db->get($this->table, $limit, $offset);
        
        return $query->result_array();
    }
}

my Rankings library:
Code:
class Rankings {

    var $id = 0;
    var $name = '';
    var $tableToRank = 'orders';

    function Rankings()
    {
        $this->obj =& get_instance();
    }
    
    function getUserList($where, $limit=10, $offset=0, $orderByField='total', $orderByDirection='desc')
    {
        $this->obj->db->where($where);
        $this->obj->db->limit($limit, $offset);
        $this->obj->db->order_by($orderByField, $orderByDirection);
        $query = $this->obj->db->query('SELECT users.id, users.username, users.firstname, users.middlename, users.lastname, SUM(orders.amount) AS total FROM orders LEFT JOIN users ON users.id = orders.user_id GROUP BY user_id');
        
        return $query->result_array();
    }
    
    function getOrganizationList($where, $limit=10, $offset=0, $orderByField='total', $orderByDirection='desc')
    {
        $this->obj->db->where($where);
        $this->obj->db->limit($limit, $offset);
        $this->obj->db->order_by($orderByField, $orderByDirection);
        $query = $this->obj->db->query('SELECT organizations.id, organizations.name, SUM(orders.amount) AS total FROM orders LEFT JOIN organizations ON organizations.id = orders.organization_id GROUP BY organization_id');
        
        return $query->result_array();
    }
}

any idea how to solve this?
#2

[eluser]lmv4321[/eluser]
Sounds like Active Record Caching is in effect. Try adding $this->db->flush_cache() after running each query.
#3

[eluser]extra_rice[/eluser]
at last someone replied... =)

thanks for the reply lmv... already did that too but to no avail... =(
#4

[eluser]lmv4321[/eluser]
Hopefully someone with more knowledge will respond and help you out, because I don't know what else to tell you.
#5

[eluser]extra_rice[/eluser]
thanks man!

i'll probably do a re-install of CI in my hosting server... thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB