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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:45:28+00:00 2026-05-23T13:45:28+00:00

In the Model class I use return $query->row(); to return single rows and return

  • 0

In the Model class I use return $query->row(); to return single rows and return $query->result(); when returning multiple rows.

On a single page I have to return single rows and multiple rows from 2 separate tables.

Table users contains general information like the user name, full name, and email address.
Table user_links contains links submitted by the respective user and has multiple rows for each user.

My query

        $this->db->select('*');
        $this->db->from('users');
        $this->db->join('user_links', "user_links.user_id = users.user_id");
        $this->db->where('users.user_id', $user_id);
        $this->db->where('user_links.user_id', $user_id);
        $query = $this->db->get();
        return $query->row(); 

In my controller I load the query in my view by

$data['row'] = $this->User_model->user_read($user_id);,

$user_id being the 3rd URL segment containing the unique user id.

Finally, in my view I retrieve rows by echo $row->first_name;

This works for single rows but how can I create a foreach loop for user links? The goal is to avoid loops for single rows and use them just for retrieving multiple rows.

  • 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-23T13:45:28+00:00Added an answer on May 23, 2026 at 1:45 pm

    If I understand your question correctly, you want to get both the user data as well as user_links data with a single query while avoiding iterating through it to get the user’s data. While this may be possible using result_array, I would advise against it since you will get 0 results when there are no entries in user_links for that particular user.

    My suggestion is that you use two queries, one to get the user from the user table, another to get user’s links from user_links table. This will also help you avoid joins.

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

Sidebar

Related Questions

I want to use Services(WCF/RIA /Web) to take data from Entity Data Model class
I have a simple model class (Part), which pulls from it's information from a
Here is my model_users class (the model it extends from doesn't have anything yet
My model: class Player(models.Model): player_name = models.CharField(max_length=50) player_email = models.CharField(max_length=50) def __unicode__(self): return self.player_name
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
Assume I have a Model class called Bird and a instance of Bird called
I have a multiple-selection enabled QListView with an Item delegate (QStyledItemDelegate) I use for
I have a rather big model Applicant: public class Applicant{ private Long id private
I currently have an Entity Framework model that collects data from a legacy database

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.