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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:28:44+00:00 2026-05-14T01:28:44+00:00

I bet this is easy but been trying for a while and can’t seem

  • 0

I bet this is easy but been trying for a while and can’t seem to get it to work. Basically I am setting up pagination and in the model below I want to pass $total_rows to my controller so I can add it to the config like so ‘$config[‘total_rows’] = $total_rows;’.

function get_timeline_filter($per_page, $offset, $source) 
    {
        $this->db->where('source', $source);
        $this->db->order_by("date", "desc");
        $q = $this->db->get('timeline', $per_page, $offset);
        $total_rows = $this->db->count_all_results();

        if($q->num_rows() >0) 
        {
            foreach ($q->result() as $row) 
            {
                $data[] = $row;                 
            }
            return $data;
        }

    }

I understand how to pass things form the Controller to the model using $this->example_model->example($something); but not sure how to get a variable from the model?

  • 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-14T01:28:44+00:00Added an answer on May 14, 2026 at 1:28 am

    I think changing your config in runtime is not good ideia, but I have 3 ways for you get the $total_rows value in your controller.

    ideia 1. You can store the value of $total_rows in the session

    ideia 2. pass the variable by reference (using &$total_rows in the function definition ex:

    function get_timeline_filter($per_page, $offset, $source, &$total_rows) 
    

    read this: http://php.net/manual/en/language.references.pass.php

    in your controller you call:

    $total_rows=0;
    $result=$this->model_name->get_timeline_filter($per_page, $offset, $source, &$total_rows);
    

    ideia 3. return the value from the function ex:

    (…)

    if($q->num_rows() >0) 
    {
        foreach ($q->result() as $row) 
        {
            $data[] = $row;                 
        }
        return $data;
    }
    
    $final_data['total_rows']=$total_rows;
    $final_data['data']=$data;
    
    return $final_data;
    

    Regards,
    Pedro

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

Sidebar

Related Questions

I bet that's an easy question for you, but searching SO or Google with
It would be easy enough to make my own system for this, but I'm
I bet I've got elementary question, but I couldn't solve it for two nights.
I'm trying to design a model for a application allowing 2 people to bet
I've been trying to build a simple prototype application in Django, and am reaching
I'm looking for something similar to this: Active navigation with jQuery - can't apply
Not sure where to put this but a site filled with working programmers is
I had this working previously, but I didn't understand how, so I'm attempting to
What's my best bet for implementing a simple chat client (2-person) in an ASP.NET
If you have $100 in your hand right now. And have to bet on

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.