Php 为个人用户显示表格
我正在尝试使用会话查看特定用户的数据。当我离开时,所有的细节都提到了 以personid=1的管理员身份登录。但当我尝试以独立用户身份登录时,表是 没有显示。我相信错误在代码的IFELSE部分。 我使用连接来组合多个表。Where语句的语法正确吗Php 为个人用户显示表格,php,mysql,sql,database,Php,Mysql,Sql,Database,我正在尝试使用会话查看特定用户的数据。当我离开时,所有的细节都提到了 以personid=1的管理员身份登录。但当我尝试以独立用户身份登录时,表是 没有显示。我相信错误在代码的IFELSE部分。 我使用连接来组合多个表。Where语句的语法正确吗 protected function selectAll() { try { $this->pdo = $this
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());
}
}
我发现了几个问题:首先,大括号没有正确匹配,因此代码有点不可预测;其次,我看不到您在哪里执行查询 请试试这个:
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
还是没有结果你确定会话变量被正确填充了吗?你有没有试过直接对数据库进行这些查询,以确保它们产生预期的结果呢?你在。。。BUSHIFT.ShiftNo=人员换档.ShiftNo和。PersonShift.PersonID。。。因此,它将被解析为BusShift.ShiftNo=PersonShift.ShiftNowhere PersonShift.PersonID。添加一个空格->。PersonShift.PersonID。。。