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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:51:55+00:00 2026-06-14T04:51:55+00:00

Okay, I have a function in my controller that works. However, I shouldn’t be

  • 0

Okay, I have a function in my controller that works. However, I shouldn’t be calling the database in the controller (as we all know). I normally can easily migrate information from a model into a controller, but I’m having a hard time with this one. I won’t even share my model version…how would you write this to a model?

    $this -> db -> select('title, price, number_sites, number_entries, white_label'); 
    $query = $this -> db -> get('pricing', 3); // limit 3 rows

    $row1 = $query->row(0); // 0 grabs first row in table: Package 1        
    $data['row1'] = $row1;

    $row2 = $query->row(1); // 1 grabs second row in table: Package 2        
    $data['row2'] = $row2;

    $row3 = $query->row(2); // 2 grabs third row in table: Package 3        
    $data['row3'] = $row3;
  • 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-14T04:51:56+00:00Added an answer on June 14, 2026 at 4:51 am

    Just copy and paste it into the model in a function you want to call:

    function dbstuff(){
        $this -> db -> select('title, price, number_sites, number_entries, white_label'); 
        $query = $this -> db -> get('pricing', 3); // limit 3 rows
    
        $row1 = $query->row(0); // 0 grabs first row in table: Package 1        
        $data['row1'] = $row1;
    
        $row2 = $query->row(1); // 1 grabs second row in table: Package 2        
        $data['row2'] = $row2;
    
        $row3 = $query->row(2); // 2 grabs third row in table: Package 3        
        $data['row3'] = $row3;
        return $data;
    }
    

    Then in your controller:

    $this->load->model('MyModel');
    $data=$this->MyModel->dbstuff();
    $this->load->view('view',$data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay i've seen this done somewhere before where you have a function that takes
Okay, I have this in my Codeigniter controller: public function post($id) { $data['query'] =
Okay, I have written a function that should convert HSL color value to RGB.
I have a function, f(a,b) , that accepts two inputs. I do not know
I have a function function callback(obj){...} Is it okay to pass in more objects
Okay, I have this code: <script language=javascript type=text/javascript> <!-- function requestPage(page) { var request
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay i have two models: posts and comments. as you can think comments has
Okay say I have a function like below: -(NSNumber *)calculate{ NSNumber *myNum = [[[NSNumber
I have a function that is a JavaScript slider. When its moved, it outputs

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.