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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:37:38+00:00 2026-06-09T06:37:38+00:00

I’m thinking about efficiency, and I’m not really sure about it one way or

  • 0

I’m thinking about efficiency, and I’m not really sure about it one way or another.

But I have a bunch of rows with multiple columns. I just need the name field from all the rows where a certain other key is a certain value. I can get all these rows like this:

$this->db->where('res_id', $res_id);
$q = $this->db->get('products');
return $q->result();

then i can foreach through the array that it returns and only use name method of each object liek this:

foreach($returned_value as $fun):
    echo $fun->name;
endforeach;

But I’m wondering, would it be more efficient to only select the name attribute from each row, and I feel stupid asking it cause I’ve been using active record forever, but how would I go about this. I realize I could write it out using the $this->db->query() function, but is there a way to specify it using the main active record commands?

  • 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-09T06:37:39+00:00Added an answer on June 9, 2026 at 6:37 am
        $this->db->select('name'); 
        $this->db->from('tblNAME');   
        $this->db->where('res_id', $res_id);
        return $this->db->get()->result();
    

    It is quicker and more efficient I suppose as you are not returning everything.

    UNTESTED

    Here is a tested function I use which you might find good reeference

    function get($id = null) 
            {
                $this->db->select('id, Username, First_Name, Last_Name, Role, Email');
                $this->db->from('user');
                if (!is_null($id)) $this->db->where('id', $id);
                $this->db->order_by('id', 'desc');
                return $this->db->get()->result();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.