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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:06:45+00:00 2026-06-18T12:06:45+00:00

I am using codeigniter to get a single result from the db, like this:

  • 0

I am using codeigniter to get a single result from the db, like this:

$user = $this->db->query("SELECT * FROM users LIMIT 1");

I am then getting the returned object and looping trough it, this way:

foreach ($user->result() as $row) { ... }

As you can imagine, there is not point in using the loop, since there is only one result. Is there a way to get users parameters without looping? Something among this line:

echo $user['name'];

Thanks in advance.

  • 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-18T12:06:46+00:00Added an answer on June 18, 2026 at 12:06 pm
    $user = $this->db->query("SELECT * FROM users LIMIT 1")->row();
    

    for having it as an object ( echo $user->name;)

    $user = $this->db->query("SELECT * FROM users LIMIT 1")->row_array();
    

    for having is as an array ( echo $user['name']; );

    $user = $this->db->limit(1)->get('users')->row(); //or ->row_array();
    

    using AR;

    $row = $user->first_row();
    

    to get the first row out of a result set ($this->db->result()), as an object (default);

    $row = $user->first_row('array');
    

    to get the first row out of a result set, as an array;

    $row = $user->row_array(1);
    

    to return a specific row (first, in this case. Just pass the <N> of the row). Works also for $user->row(1);

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

Sidebar

Related Questions

I'm using $this->db->get()->row_array() in Codeigniter to get a single row of results from the
I'm using CodeIgniter 2 (latest build) ...let's say I have this query: $CI->db->select(FileName, GUID,
I'm using Codeigniter's Active Record Class. So the query looks something like this: $query
I'm using codeigniter framework and I'm getting this error when I've submitted my form:
I'm using codeigniter to create a search page. I'd like to rewrite a GET
I am outputing a simple list of options from dynamic select menus using Codeigniter/MYSQL.
How to get records from Excel sheet to Mysql database using Codeigniter php?
I'm making a query in PHP using CodeIgniter to get the data that I
I'm using codeigniter for a project. The URL is segmented like this: example.com/admin/events example.com/admin/events/add
hi i am using codeigniter , and i have a table like this i

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.