2016-04-29 7 views
1

Ich versuche, alle Berichte von report abzurufen, wenn die Session StaffID mit StaffID in der reports Tabelle übereinstimmt.Daten abrufen, wenn die Sitzungs-ID mit der Tabelle übereinstimmt

Report_Name, ReportDate and ReportID are part of the report table 

das ist, wie ich denke, es

ReportID holen Report_Name und ReportDate von report wo ReportID von Read_Report Streichhölzer ReportID von report wenn Session StaffID = StaffID in Read_Report

gehen und Th meine Frage ist

function get_read_report() 
    { 
     $this->db->select('report.Report_Name, report.ReportDate, report.ReportID') 
      ->from('Read_Report') 
      ->join('Read_Report', 'report.ReportID = Read_Report.ReportID') 
      ->where('StaffID', $this->session->userdata("StaffID")); 
     return $result = $this->db->get(); 
    } 

ich diesen Fehler

Fehlernummer erhalten: 1066

Not unique table/alias: 'Read_Report' 

SELECT `report`.`Report_Name`, `report`.`ReportDate`, `report`.`ReportID` FROM `Read_Report` JOIN `Read_Report` ON 

report. ReportID = Read_Report. ReportID WHERE StaffID = '3'

Filename: models/report/Report_model.php 

Line Number: 91 

Controller-Code

function my_read_reports() 
    { 
     $data = array(); 

     if ($query = $this->report_model->get_read_report()) { 
      $data['reports'] = $query; 
     } 

     $this->template['middle'] = $this->load->view($this->middle = 'pages/read_reports_view', $data, true); 
     $this->layout(); 
    } 
+0

Sie nur richtige Tabelle Beitritt zum Zeitpunkt verpasst zu ändern. –

Antwort

3

Sie benötigen eine Tabelle mit report Tabelle nicht die gleiche Tabelle

ändern

->join('Read_Report', 'report.ReportID = Read_Report.ReportID') 
beitreten

TO

->join('report', 'report.ReportID = Read_Report.ReportID') 

Sie benötigen eine Abfrage

$this->db->select('report.Report_Name, report.ReportDate, report.ReportID') 
      ->from('report') 
      ->join('Read_Report', 'report.ReportID = Read_Report.ReportID') 
      ->where('Read_Report.StaffID', $this->session->userdata("StaffID")); 
     $result = $this->db->get(); 
     return $result->result();// fetch data then return 
+0

hmm bekommen Undefinierte Eigenschaft: mysqli :: $ ReportDate – Beep

+0

'ReportDate' gehören zu welcher Tabelle ?? – Saty

+0

Berichtstabelle, gleich mit Report_Name und ReportID – Beep

2

Ihre Abfrage sollte

$this->db->select('report.Report_Name, report.ReportDate, report.ReportID') 
     ->from('Read_Report') 
     ->join('report', 'report.ReportID = Read_Report.ReportID') 
     ->where('StaffID', $this->session->userdata("StaffID")); 
     return $result = $this->db->get(); 
Verwandte Themen