Multiple/Sub quries with codeigniter

Posted by user1011713 on Stack Overflow See other posts from Stack Overflow or by user1011713
Published on 2012-07-09T03:12:29Z Indexed on 2012/07/09 3:15 UTC
Read the original article Hit count: 130

Filed under:
|
|

I just started with Codeigniter and this is driving me nuts. I have a query that determines whether a user has bought any programs. I then have to use that program's type category to run and determine how many times he or she has recorded a query in another table. Sorry for the confusion but the code hopefully makes sense.

I'm having problem returning the two arrays from my Model to my Controller to onto the view obviously.

function specificPrograms() {
$specific_sql = $this->db->query("SELECT program,created FROM  `assessment`  WHERE uid = $this->uid");
if($specific_sql->num_rows() > 0) {
foreach ($specific_sql->result() as $specific) {        
$data[] = $specific;
$this->type = $specific->program;   
}
return $data;
}   

$sub_sql = $this->db->query("SELECT id FROM othertable WHERE user_id_fk = $this->uid and type = '$this->type'");
if($sub_sql->num_rows() > 0) {
foreach ($sub_sql->result() as $otherp) {       
$data[] = $otherp;
}
return $data;
}

}

Then in my Controller I have,

$data['specific'] = $this->user_model->specificPrograms();
$data['otherp'] = $this->user_model->specificPrograms();

Thanks for any help.

© Stack Overflow or respective owner

Related posts about php

Related posts about sql