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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:17:53+00:00 2026-05-31T23:17:53+00:00

i am using codeigniter. i have a table to be displayed in a view

  • 0

i am using codeigniter. i have a table to be displayed in a view file. so i have a model where i fire a query to get the data from table.

function my_active_requests()
    {
        $user_id =  $this->session->userdata('user_id');
        $this->db->select('id,request_date,required_by_date');
            $this->db->where('requested_by',$user_id);
            return $this->db->get('requests');
            ///also tried with 
            //$query = $this->db->get('requests');
        ///$number_of_rows = $query->num_rows;
            //return $query;
            //return $number_of_rows;
            //but no result
     }

this is the model function.

this is my controller

function my_active_req()
        {

            $this->bloodline_model->my_active_requests();
                    //also tried without this// 
                    $query = $this->db->get('requests');
                    //and this//
            $number_of_rows = $query->num_rows;
            $this->load->view('my_active_req');
        }   

and this is my view

<?php foreach ($query->result() as $row) { ?>
        <tr>
            <td><?php echo $row->id; ?></td>
            <td><?php echo $row->request_date; ?></td>
            <td><?php echo $row->required_by_date; } ?></td>
        </tr>
    </table>

but the error is undefined variable $query.
i think , i am not able to return the $query and other data from my model to controller and controller to my view.
Please provide me with the solution.
`

  • 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-05-31T23:17:55+00:00Added an answer on May 31, 2026 at 11:17 pm

    Change this line:

    <?php
    $this->load->view('my_active_req', array(
        'query' => $query
    ));
    

    The second parameter of the view() loader function allows you to pass variables into the view.

    However, you’re largely circumventing the purpose of MVC separation. You want the controller to “ask” for information from the model (not just straight from the database; otherwise, what’s the point of a model?), and then “pass” it to the view. The controller knows what the view needs to function.

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

Sidebar

Related Questions

I have this syntax for grabbing some data from database, I using codeigniter's active
I have this function on my controller (Im using CodeIgniter) that reads the database,
I have a validation function I'm using inside of codeigniter. function valid_image() { if
I have two tables, categories and products. I am using CodeIgniter. Categories CREATE TABLE
Using CodeIgniter's Active Record class and MySQL, I have a table of posts with
hi i am using codeigniter , i use the insert_batch function . i have
Currently working on a bespoke ecommerce application using Codeigniter. I have a products table
hi i am using codeigniter , and i have a table like this i
I am using Codeigniter framework and I have a form with input fields. When
I'm using CodeIgniter (because it's awesome) and I have something like: <?php echo anchor(/,

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.