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

  • Home
  • SEARCH
  • 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 8246429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:30:13+00:00 2026-06-07T22:30:13+00:00

In my controller I went from getting the data right there (which worked fine):

  • 0

In my controller I went from getting the data right there (which worked fine):

$data['query'] = $this->db->query("MY DB QUERY");  
$this->load->view('shopci_view', $data);

to grabbing the data from a class model function:

    class Shopci_model extends CI_Controller {

      function __construct()
      {
        parent::__construct(); //model constructor
      }

      //display sale itmes on shopci_view.php
      function sale_items()
      {    

        $query = $this->db->query('MY DB QUERY - SAME AS ABOVE');

        return $query->result();
      }

  }

new controller function:

//load model, auto connect to db
$this->load->model('Shopci_model', '', TRUE);    
//Display items for sale
$data['query'] = $this->Shopci_model->sale_items();  
$this->load->view('shopci_view', $data);  

ERROR:

Fatal error: Call to a member function result() on a non-object in
shopci_view

This is the line in the view that worked before I switched to the model (didn’t change view):

<?php foreach($query->result() as $row): ?>

Any help is appreciated.

Thank You.

  • 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-07T22:30:15+00:00Added an answer on June 7, 2026 at 10:30 pm

    In your model you return the $query as a result() array to the controller.

    So you cannot then use ‘foreach $query->result()’ again – because you have already done that;

    This should work

      <?php foreach($query as $row): ?> 
    

    OR if you want – just change the model from

     return $query->result(); 
    

    to

     return $query;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My controller get datas from database model, and sends them to view. In view
I went through the Book and I've copied code from the section http://book.cakephp.org/view/1460/RSS but
I went through this tutorial Your First iPhone Application and it worked great. My
Iam trying to return json data from codeigniter view. but my code is not
This is my code from my controller: MGEntities db = new MGEntities(); [HttpPost] public
I have a tab bar controller view that loads a record from an api
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
The controller function: function signup() { $bool1 = $this->form_validation->run('username'); $bool2 = $this->form_validation->run('email'); $bool3 =
How do you put two different function outputs from the same controller into the
I've set a variable so it can be used from the controller to pass

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.