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.sstatic.net/zSHSQ.png

I am having trouble figuring out what I need to do for some of my tables
For example 1:M or M:M
- 1 procedure has 1 or many procedure_event
- a procedure_event may or may not have use resources
- 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!