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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:46+00:00 2026-06-14T20:23:46+00:00

new to CodeIgniter and MVC/OOP as well. My current problem that I am trying

  • 0

new to CodeIgniter and MVC/OOP as well. My current problem that I am trying to work through involves 2 tables.


Gallery Table

id

name

clientID


Client Table

id

Name


The gallery[‘clientID’] references the client[‘id’] so I can retrieve the name. Currently my gallery_model.php file looks like

class Gallery_model extends CI_Model
    {

        public function __construct()
        {
            $this->load->database();
        }

    //Get all in progress galleries from client
    public function get_progress($id = FALSE , $clientRef = '205')
    {
        if($id == FALSE) {
            $query = $this->db->get_where('gallery', array('clientRef' => $clientRef, 'finish' => '0' ));
            return $query->result_array();
        }
    }
    //Get all proofed galleries from client
    public function get_proofed($id = FALSE , $clientRef = '205')
    {
        //get all galleries from client
        if ($id == FALSE) {
            $query = $this->db->get_where('gallery',array('clientRef' => $clientRef, 'finish' => '1'));
            return $query->result_array();
        }
    }

    //get the gallery selected
    public function get_gallery($id , $clientRef = '205')
    {
        //This returns individual galleries
        $query = $this->db->get_where('gallery', array('id' => $id));
        return $query->row_array();
    }
}

My controller looks like:

    public function index()
    {
        //Proofed Albums
        $data['gallery'] = $this->gallery_model->get_proofed();
        //Albums that are in progress
        $data['in_progress'] = $this->gallery_model->get_progress();

        $this->load->view('templates/header',$data);
        $this->load->view('gallery/index',$data);
        $this->load->view('templates/footer');
    }

Then the view’s out put is

$gallery['name'] - $gallery['clientId']

What is the best practice for something like this. I know it’s probably simple, but I want to start out doing this correctly. Should I use $this->db->join();

Thanks in advance for the help on 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-06-14T20:23:47+00:00Added an answer on June 14, 2026 at 8:23 pm

    Using $this->db->join() is indeed the best (and the only way done via Active Records without adding your own SQL) way to get information from several tables all in one query.

    You’re probably already aware of this, but just in case (and for the benefit of future people visiting this page), the CodeIgniter User Guide has a nice page detailing how to use Active Records.

    The default of Inner Join should be fine for your purposes. If you have gallery entries without clients linked to them and you want them to be included in the results, then you may want to consider the other types of join, which you can read about here.

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

Sidebar

Related Questions

I'm new to MVC and Codeigniter and am trying to get a class working.
I'm fairly new to Codeigniter as well as MVC and I'm having a bit
I'm new to codeigniter and building web applications using MVC. I'm trying to wrap
I'm new to MVC (I'm using codeigniter) and was wondering where I should put
I'm new in codeigniter I have problem I use my OS X Lion, and
Fairly new to CodeIgniter, still grasping the MVC approach. I'm just wondering what's the
i'm new to codeigniter, i have a problem Is it possible to have same
I am trying to get started with the PHP MVC framework, CodeIgniter. I am
I am still new at PHP and the MVC concept. I have been trying
I'm new to CodeIgniter. I notice that all CodeIgniter folders (cache, config, controllers, core,

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.