php - How to CREATE a 'VIEW(SQL)' in CodeIgniter and SELECT data from it? -
i have query needs check whether record still active before includes in query. problem record status of record in database , know cant join tables different databases.
what want create view other database , i'll join view query. problem how can create view , select data in codeigniter?
thanks in advance.
by way, im not 1 designed database. -company defined-
heres sample of query, not exact 1 since includes lot of tables. hope give hint of i'm trying do.
select count(idno), course, sum(student_balance) student_balances school_term = '2013' , student_balance > 0 group course order course all student records there selected regardless if enrolled or not. there table containing enrolled students of current school year table from database. want count records of students enrolled.
we know can't join tables different databases
not sure if applicable in case, here few posts querying across db's:
querying multiple databases @ once
php mysql joins across databases
https://stackoverflow.com/a/5698396/183254
at rate, don't need use join; query other db see if thing active
$db2 = $this->load->database('otherdb', true); $active = $db2->query('select is_active blah... if($active) { //do other query } update
this isn't syntactically correct, should point in right direction. always, user guide.
// load other db $db2 = $this->load->db('otherdb',true); // enrolled student id's other db $active_students = $db2->query('select id students enrolled = 1')->result(); // query db want $this->db->select('count(idno), course, sum(student_balance)'); $this->db->where('school_term',2013); $this->db->where('student_balance >',0); // where_in limit query id's in $active_students $this->db->where_in('id', $active_students); // finally, execute query on student_balances table $balances = $this->db->get('student_balances');
Comments
Post a Comment