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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:10:45+00:00 2026-05-29T16:10:45+00:00

I’ve been hacking away at CodeIgniter for a week or so, only because I

  • 0

I’ve been hacking away at CodeIgniter for a week or so, only because I don’t have the ability to understand RoR. I’ve managed to create some rudimentary models, views and controllers but I am now at a point where I have to start considering the fact that I am using multiple models.

My question may be related to basic SQL, but I expect that there is functionality in CodeIgniter which permits returned rows from having certain data fields be replaced with information from other tables. If I knew what this concept was called in SQL, then I would at least know what to look for in the Docs, but I am only a beginner. I’d like to at least have some basic knowledge here so I can read up on the details.

For example, let’s say I have a companies table (company model) which has only two fields, an ‘id’ set as the primary key, and a ‘Company_name’ which is varchar. In addition, let’s say I have a table of stores (store model) which has four fields like ‘address’, ‘id’ (primary key), and company_id which is the index in the companies table.

The companies could be something like:

ID    Company_name
------------------------------------------------
1     CompanyA
2     CompanyB
3     CompanyC

The stores could be something like:

ID    Store_name   Address         Company_ID 
------------------------------------------------
1     StoreA       12 Main St.     1
2     StoreB       33 First Ave.   1
3     StoreC       9 Broad Rd.     2
4     StoreD       873 Wide Blvd.  3
5     StoreE       8103 Water St.  1

Where the CompanyID field relates the table back to the companies table.

If I do a basic query in CodeIgniter to return all ‘stores’ as:

$this->db->get('stores');

I will be able to go through the result row by row, but the Company_ID field will still be just an index value. Is there a way to perform a query such that the Company_ID field is automatically replaced by the appropriate company name from the companies table in the returned results? The idea would be that I want to create a resulting table which looks like the one below:

Store Name    Address           Company Name
------------------------------------------------
StoreA        12 Main St.       CompanyA
StoreB        33 First Ave.     CompanyA
StoreC        9 Broad Rd.       CompanyB
StoreD        373 Wide Blvd.    CompanyC
StoreE        8103 Water St.    CompanyA

An easy real-world example would be fast food chain stores belonging to a parent company or something like that.

Not sure how else to explain this. :/

  • 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-29T16:10:46+00:00Added an answer on May 29, 2026 at 4:10 pm

    What you’re looking for is a SQL join. You can do it in CodeIgniter like this.

    $this->db->select("stores.Store_name, stores.Address, companies.Company_name");
    $this->db->from("stores");
    $this->db->join("companies", "companies.ID=stores.Company_ID");
    $query = $this->db->get();
    

    Personally, I just prefer to write the query myself.

    $query = $this->db->query("select stores.Store_name, stores.Address, companies.Company_name from stores inner join companies on companies.ID=stores.Company_ID");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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 am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.