2014-09-25 23 views
0

我正在嘗試使用會話查看特定用戶的數據。所有的細節出現時,我登錄作爲其personid = 1的管理員。但是,當我嘗試作爲一個單獨的用戶登錄,該表是 不顯示。我相信這個錯誤在代碼的IFELSE部分。 我已經使用連接來組合多個表。 Where語句的語法是否正確?個人用戶的顯示錶

protected function selectAll() { 

    try {             

     $this->pdo = $this->Connect();    

     session_start(); 

此部分用於由管理員

 if(isset($_SESSION["personid"]) && $_SESSION["personid"] === '1') { 
     $sql = "select * from PersonShift "     
      . " inner join Person on Person.PersonID = PersonShift.PersonID"     
      . " inner join Role on Role.RoleID = PersonShift.RoleID" 
      . " inner join BusShift on BusShift.ShiftNo = PersonShift.ShiftNo";    

     } 

看到所有班次在本節中,在用戶登錄只能看到他的特別班次

 else if(isset($_SESSION["personid"]) && $_SESSION["personid"] !== '1') { 

    $sql = "select * from PersonShift "     
      . " inner join Person on Person.PersonID = PersonShift.PersonID"     
      . " inner join Role on Role.RoleID = PersonShift.RoleID" 
      . " inner join BusShift on BusShift.ShiftNo = PersonShift.ShiftNo" 
      . "where PersonShift.PersonID = ".$_SESSION['personid']; 

     }        

     $stmt = $this->pdo->prepare($sql);       


     }        

     $this->result = $stmt->fetchAll();        

     $this->pdo = null;       

     return $this->result;             

       } catch (\Exception $ex) { 

       throw new \Exception($ex->getMessage()); 

     }      

     }   
+0

你不必'... BusShift.ShiftNo = PersonShift.ShiftNo之間的空間,PersonShift.PersonID ...'所以將被解析爲'BusShift.ShiftNo = PersonShift.ShiftNowhere PersonShift.PersonID'。添加一個空格 - >'。 「Where PersonShift.PersonID ...' – Sean 2014-09-25 02:57:20

回答

0

我看到一對夫婦那裏的問題:首先,大括號不正確匹配,所以代碼是不可預測的;第二我沒有看到你執行查詢的地方。

請試試這個: 「`和`」

protected function selectAll() 
{ 
    try {             
     $this->pdo = $this->Connect();    
     session_start(); 

     if(isset($_SESSION["personid"]) && $_SESSION["personid"] === '1') 
     { 
      $sql = "select * from PersonShift "     
      . " inner join Person on Person.PersonID = PersonShift.PersonID"     
      . " inner join Role on Role.RoleID = PersonShift.RoleID" 
      . " inner join BusShift on BusShift.ShiftNo = PersonShift.ShiftNo";    
     } 
     else if(isset($_SESSION["personid"]) && $_SESSION["personid"] !== '1') 
     { 
      $sql = "select * from PersonShift "     
        . " inner join Person on Person.PersonID = PersonShift.PersonID"     
        . " inner join Role on Role.RoleID = PersonShift.RoleID" 
        . " inner join BusShift on BusShift.ShiftNo = PersonShift.ShiftNo" 
        . "where PersonShift.PersonID = ".$_SESSION['personid']; 

     } // end if 

     $stmt = $this->pdo->prepare($sql); 

     $stmt->execute(); // Execute was missing 

     //} This was misplaced 

     $this->result = $stmt->fetchAll();        

     $this->pdo = null;       

     return $this->result;             

    } catch (\Exception $ex) { 
     throw new \Exception($ex->getMessage()); 
    }      
} // end function 
+0

Sorted that out..still no results – 2014-09-25 02:05:25

+0

你確定會話變量是否被正確填充?你是否直接對數據庫嘗試了這些查詢,以確保它們帶出預期的結果? – 2014-09-25 02:08:31

相關問題