Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:21:18+00:00 2026-06-07T05:21:18+00:00

I just started with Codeigniter and this is driving me nuts. I have a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:21:19+00:00Added an answer on June 7, 2026 at 5:21 am

    Based on your comments above, I suggest one query which returns the results you need. The result set of this will look like this:

    +----------+------------+------+
    | program  | created    | uses |
    +----------+------------+------+
    | football | 2001-01-01 | 12   |
    +----------+------------+------+
    | baseball | 2007-01-01 | 21   |
    +----------+------------+------+
    
    
    SELECT 
      assessment.program, 
      assessment.created, 
      count(othertable.user_id) as uses
    FROM  assessment
    JOIN othertable 
      ON othertable.user_id_fk = assessment.uid
      AND othertable.type = assessment.program
    WHERE assessment.uid = $this->uid
    GROUP BY assessment.program
    
    ... model ...
    
    function specificPrograms() {
      $results = $this->db->query($sql_from_above);
      if($specific_sql->num_rows() > 0) {
      foreach ($specific_sql->result() as $program_data) {        
        $data[] = $program_data;
      }
      return $data;
    }
    
    ... meanwhile in controller ...
    
    
    $programs_used = $this->user_model->specificPrograms();
    foreach($programs_used as $program_use_data) {
      // On first iteration, this is true:
      // $program_use_data['program'] == "football"
      // $program_use_date['uses'] == 12
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started to play with CodeIgniter 1.7.2 and imendialtly noticed that there is
I've just started to use codeigniter and I have a question. I am using
I've just started learning CodeIgniter, and I'm following this authentication tutorial by nettuts+. I
I am fairly new and just started to use Codeigniter, and have come across
I just started learning using AJAX with Codeigniter. On my view, I have a
I just have started working with codeIgniter and want to know how things in
Just started mongo and started having issue with querying already. i have a collection
Ok...so I've just started playing around with Codeigniter. I've followed the two tuts on
I just started using CodeIgniter after using Zend for a while. My new site
I just got started with CodeIgniter and am wondering will it slow things down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.