• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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?


Messages In This Thread
problem with multiple query but different libraries used - by El Forum - 11-08-2008, 08:38 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.