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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:09:07+00:00 2026-05-24T11:09:07+00:00

To make this a simple as possible to understand I am going to give

  • 0

To make this a simple as possible to understand I am going to give you all the details I can so I can figure out this problem.


Okay so my problem is that my query that fetches me ONE record from my database is returning what appears to be duplicate values of the same record in multiple arrays. When I check my query result all my tables are duplicated and placed into arrays – one array for each duplicated record (or row).

The cause of this I think is my 1 –> Many relationship table (Procedure –> Procedure_event)

Here is my shema (you will see procedure and procedure_event) are 1: M relationship.

https://i.stack.imgur.com/SggnD.png


Here is my query result as you can see my tables (apart from procedure event) are repeated with the same data in each array. The quantity of arrays returned is dependant on how many procedure_event rows there are linked to procedure.

In this list there are three! –> http://pastebin.com/pc53Pmgf

To illustrate to you what is happening here is a diagram:

Query Result:

procedure row x —> procedure_event row x

procedure row x —> procedure_event row x+1

procedure row x —> procedure_event row x+1

What I want to returned is this (no duplication of other tables):

procedure row x —> procedure_event x

           ---> procedure_event x+1

            ---> procedure_event x+1

Here is my query in Codeigniter Active Record

public function view_record($record_id)
        {
            //The criteria used for WHERE is a variable with array of procedure_id = record_id that is passed to function
            //e.g. Record id = 2419
            $criteria = array 
            (
                'procedure_id' => $record_id
            );

            //this selects the columns from procedure table for use in joins 
            $this->db->select('*');
            //this is the table I want to use the columns from
            $this->db->from ('procedure');

            //this joins the patient row that matches its ID to the patient ID in the procedure table
            $this->db->join('patient', 'patient.patient_id = procedure.patient_id', 'left');

            //this joins the department row that matches its ID to the patient ID in the procedure table
            $this->db->join('department', 'department.department_id = procedure.department_id', 'left');

            //this joins the procedure_name row that matches its ID to the patient ID in the procedure table
            $this->db->join('procedure_name', 'procedure_name.procedure_name_id = procedure.name_id', 'left');

            //this joins the dosage row that matches its ID to the patient ID in the procedure table]
            $this->db->join('dosage', 'dosage.dosage_id = procedure.dosage_id', 'left');

            //----->This is what is causing the problem -- try a different JOIN?
            $this->db->join('procedure_event', 'procedure.procedure_id = procedure_event.procedure_id' , 'left');

            //this selects the row in procedure table that matches the record number
            $this->db->where('procedure.procedure_id', $record_id);

            //gets all the data from the query
            $result = $this->db->get();


            //
            if ($result->num_rows >0)
            {
                return $result->result();
            }

            else
            {
                return FALSE;

            }


        }

I hope this is clear to everyone. I hope there is a way to solve this otherwise I am going to be stuck as I do not know how to deal with all this repeated data as it is messing up my foreach loops.

In the words of Princess Leiah

“Help me Obi’wan, your my only hope!”

Thanks!

  • 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-24T11:09:08+00:00Added an answer on May 24, 2026 at 11:09 am

    So, if I understand you correctly, you want the procedure_event to be returned as a nested array? Is this right?

    If so, I’m not sure if Codeigniter offers a way to do that directly. Your best bet is probably to process the arrays that you are currently getting using php, to put the data into the nested non-duplicate format that you want.

    You could also break it down into 2 queries. One to get all the procedure data, using all the joins but leaving out the procedure_event joint. Then do a second query where you just join procedure to procedure_event. It would then be a simply matter to loop through the result and prepare the data the way you would like it.

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

Sidebar

Related Questions

I can not get to make this comparison in this simple code error ..
Hey guys, this is simple but I can't make it workn... blah! I have
I followed this tutorial to make a simple website where you can enter blog
Ho to make this simple xml with php using DOM? Full code will be
I was wondering which is the way to make this simple (and maybe stupid)
I will make this quick and simple I have a query and I want
Simple question, how make this code working ? public class T { public static
After loading a PHP template (using jQuery's load function), this simple script won't make
I would like to make a simple desktop application to learn this kind of
This is probably going to be a really simple explanation, but I'm going to

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.