Note that there are some explanatory texts on larger screens.

plurals
  1. POset relation grocery crud error
    text
    copied!<p>I have 2 tables</p> <pre><code>CREATE TABLE `tbl_patient` ( id_patient INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(25) NOT NULL DEFAULT "not available", att1 VARCHAR(5 ) NOT NULL DEFAULT "att1", att2 VARCHAR(25) NOT NULL DEFAULT "att2", att3 VARCHAR(25) NOT NULL DEFAULT "att3", CONSTRAINT `uc_Info_patient` UNIQUE (`id_patient`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; </code></pre> <p>and</p> <pre><code>CREATE TABLE `tbl_patient_medicine` ( id_patient_medicine INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, id_patient INTEGER NOT NULL, name_medicine VARCHAR(50) NOT NULL DEFAULT "", dosis VARCHAR(50) NOT NULL DEFAULT "", start_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, treatment VARCHAR(50) NOT NULL DEFAULT "", times_per_day VARCHAR(50) NOT NULL DEFAULT "", CONSTRAINT fk_ID_Patient_Medicine FOREIGN KEY (id_patient) REFERENCES `tbl_patient`(id_patient) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; </code></pre> <p>As you can see table patient_medicine is the intermediate table of between tbla_medicines, and table patient. </p> <p>Now I want to consult all data from tbl_patient_medicine with grocery crud <a href="http://sqlfiddle.com/#!2/5960f/4" rel="nofollow">like in this sqlfiddle</a></p> <p>supossing I pass the id in the uri (in the example will be id_patient=1) I have</p> <pre><code>public function details_medication($my_id = 0) { try{ $crud = new grocery_CRUD(); $crud-&gt;where('id_patient',$my_id); $crud-&gt;set_table('tbl_patient_medicine'); //HOW TO DO IT? $crud-&gt;set_relation('id_patient', 'tbl_patient', 'id_patient'); $output = $crud-&gt;render(); $this-&gt;_output($output); }catch(Exception $e){ show_error($e-&gt;getMessage().' --- '.$e-&gt;getTraceAsString()); } } </code></pre> <p>SO I have tried different ways but got errors like this:</p> <pre><code>A Database Error Occurred Error Number: 1052 Column 'id_patient' in where clause is ambiguous SELECT `tbl_patient_medicine`.*, j7a675883.id_patient AS s7a675883 FROM (`tbl_patient_medicine`) LEFT JOIN `tbl_patient` as j7a675883 ON `j7a675883`.`id_patient` = `tbl_patient_medicine`.`id_patient` WHERE `id_patient` = '1' LIMIT 25 </code></pre> <p>Line Number: 87</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload