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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:01:54+00:00 2026-05-24T06:01:54+00:00

I am trying to make a query in Codeigniter that will allow a user

  • 0

I am trying to make a query in Codeigniter that will allow a user to retrieve a record they submitted in the past to my database.

This is my schema:

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

enter image description here

I am having trouble figuring out what I need to do for some of my tables

For example 1:M or M:M

  1. 1 procedure has 1 or many procedure_event
  2. a procedure_event may or may not have use resources
  3. 1 procedure has 1 or many staff

I think I need to use Select, Joins for this and I have got some of it completed but for the Many to Many relationships and linked tables I am confused how to do them.

This is what I have got so far in terms of code but it is not returning any rows so I think it is wrong:

    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
        $criteria = array 
        (
            'procedure_id' => $record_id
        );

        //this selects the columns from procedure table for use in joins 
        $this->db->select('procedure.procedure_id, procedure.patient_id, procedure.department_id, procedure.name_id , procedure.dosage_id');
        //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', 'inner');

        //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', 'inner');

        //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', 'inner');

        //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', 'inner');

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

        /*
        Code for other tables:
        I need help with

        procedure_event, staff, resources, hr

        */

        //this part I think is wrong
        $result = $this->db->get();


        //
        if ($result->num_rows >0)
        {
            echo "There is Data!";

        }

        else
        {
            echo "No Data!";

        }

}

I get back a message saying “No Records” however there is data in my tables etc:

So my query so far must be wrong.

Thanks for your time!

  • 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-24T06:01:55+00:00Added an answer on May 24, 2026 at 6:01 am

    Firstly, I personally consider it easier to write as complex queries as this on in pure text, rather then using Active Records.

    All your joins uses inner; that is that all rows need to find a partner in the other table. If any of these doesn’t exist you get 0 rows. Consider using LEFT JOIN, as previously suggested.

    Do all of these tables contain data at the moment?

    Do need absolutely a partner row in everyone of these tables, or do you count on cases where rows are missing?

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

Sidebar

Related Questions

I'm trying to make a query that will check for duplicates, and if I
I'm trying to make a query that would do something like this... id |
I'm trying to make a query that selects all messages from a specific user
hi i am trying to make a query that will run records from a
I'm trying to make a query that looks at a single table to see
I'm trying to make a query that grabs a single row from an SQL
I'm trying to make a query in HQL that see if the id of
I'm trying to make a query function that accepts two datetime.date object(start_date and end_date),
Using the vs2008 query builder, I’m trying to make a query that gets a
I am trying to make an MDX query that can tell me how many

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.