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 9147291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:57:09+00:00 2026-06-17T10:57:09+00:00

i am new with codeigniter.I have written controller,model.view. I want to execute the another

  • 0

i am new with codeigniter.I have written controller,model.view.

I want to execute the another query in the model which having the “ID” from first model query in the where condition and pass the seperate results for both the both query in same view.

i have explain it in model and view.
how can i do this.need some syntax how can i do this.
or is this correct way or do somwthing??

Controller

class demo extends CI_Controller
{
    function getRecords()
    {
        $offset = trim($this->input->get('off'));
        $this->load->model('demo_model');
        $data = $this->demo_model->get_messages($offset);
        $return = $this->load->view('demo_view',array('records'=>$data),true);
        die($return);
    }   
}

Model

class demo_model extends CI_Model
{
    function get_messages($offset = 0)
    {
        $q = $this->db->query(" select Id,cloum2 from table");

        //  want to use ID from above query in to second query

        //  Like sql="select * from table where id='$id'" ; 

        //  and how i pass the separate result for both query inthe view

    return $q->result_array();
     }

}

View demo_view;

<?php foreach($records as $row) :?>
 <div> do something with $row </div>

 <div> //want use second query foreach here  </div>
<?php endforeach ;?>
  • 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-17T10:57:11+00:00Added an answer on June 17, 2026 at 10:57 am

    Both queries will return PHP arrays so you can do something like.

    MODEL

    function get_messages($offset = 0)
    {
        $q = $this->db->query(" select Id,cloum2 from table");
       return $q->result_array();
     }
    
     function get_id($id){
        $q = $this->db->query("select * from table where id='$id'");
       return $q->result_array();
      }
    

    CONTROLLER

      class demo extends CI_Controller{
          function getRecords(){
                $offset = trim($this->input->get('off'));
               $this->load->model('demo_model');
               $data = $this->demo_model->get_messages($offset);
               for($c=0;$c<count($data);$c++){
                  $data[$c]['innerRow']=$this->demo_model->get_id($data[$c]['id']);
               }
               $return = $this->load->view('demo_view',array('records'=>$data),true);
               die($return);
         }
    

    VIEW

         <?php foreach($records as $row) :?>
              <div> do something with $row </div>
             <div>  
                 <?php foreach($row['innerRow'] as $innerrow) :?>
                  ......
                 <?php endforeach ;?>
             </div>
    
         <?php endforeach ;?>
    

    (But this isn’t such a good idea as you will run a bunch of queries to the model. Its better to think of a nicer query)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have download the new codeigniter 2.0 and put my controller,model and view files
I am new in codeigniter. I have implemented a simple login system. I want
I'm relatively new to CodeIgniter and am making my first CI project in which
I have taken over a project written in CodeIgniter, which I have never used
I'm new to CodeIgniter and I have this function which I use in more
I have a view in my codeigniter app that gets an array from the
I am new to Codeigniter, and I have trouble with the pagination class. From
I'm a bit confused here. I have a simple controller which loads a view.
I am new to Codeigniter. This is my first experience in Codeigniter. I have
I'm new to CodeIgniter and have come into an issue with the insertion of

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.