これをできるだけシンプルにするために、私はできることすべてを詳細に説明しますので、この問題を理解することができます。私のクエリは結果を複製していますか? MySQL/PHP/Codeigniter
わかりました私の問題は、私のクエリは私のデータベースからONEレコードが複数のアレイ内の同じレコードの重複した値と思われるものを返している私を取得しているということですので。私のクエリ結果をチェックすると、すべてのテーブルが複製され、配列に配置されます。複製されたレコード(または行)ごとに1つの配列です。
私は私の1だと思うこの原因 - >多くの関係テーブル(手順 - > Procedure_event)
ここでは私のシェマです(プロシージャとprocedure_eventが表示されます)1:Mの関係。あなたはは、各アレイ内の同じデータで繰り返される(手順イベントとは別に)私のテーブルを見ることができるよう
は、私のクエリの結果です。返される配列の数は、procedure_eventの行がの手順にリンクされているかどうかに依存します。
このリストには3つあります! - >ここで何が起こっているかあなたに説明するためにhttp://pastebin.com/pc53Pmgf
は図である。
クエリ結果:
手順行のx ---> procedure_event行のx
手順行のx ---> procedure_event行x + 1
手順行x --->手続き行x + 1
私が返さたいのは、この(他のテーブルの無重複)である:ここでは
手順行のx ---> procedure_event X
---> procedure_event x+1 ---> procedure_event x+1
は私のクエリですin Codeigniterアクティブレコード
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;
}
}
これは誰にとっても分かりやすいことを望みます。私はこの問題を解決する方法があることを願っています。そうしないと、この繰り返しデータを処理する方法がわからないので、私のforeachループを台無しにしてしまいます。プリンセスLeiahの言葉で
は
「私にObi'wan、あなたの私の唯一の希望を助けて!「
ありがとう!