我正在嘗試使用會話查看特定用戶的數據。所有的細節出現時,我登錄作爲其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());
}
}
你不必'... BusShift.ShiftNo = PersonShift.ShiftNo之間的空間,PersonShift.PersonID ...'所以將被解析爲'BusShift.ShiftNo = PersonShift.ShiftNowhere PersonShift.PersonID'。添加一個空格 - >'。 「Where PersonShift.PersonID ...' – Sean 2014-09-25 02:57:20