通过检查employeeID根据登录用户显示信息

时间:2016-12-29 06:20:40

标签: javascript php html sql-server active-directory

我正在使用Active Directory来验证用户身份。 现在我使用下面的php来存储已登录用户的Employee_id:

if(isset($data[$i]["employeeid"][0]))
{
$user= $data[$i]["employeeid"][0];
session_start();
$_SESSION['id']=$user;
}

现在,在身份验证之后,用户将被带到配置文件。 在配置文件中,我想根据已登录的用户回显所选信息。

所以我使用下面的php根据他们的employee_id选择用户并回显信息:

<div id="co-workers" class="leadboardcontent" style="display:none">

<div class="leaderboard">
  <?php  if ( $_SESSION['id'] == '1981')?> {
  <ol>
    <li>
        <mark>
      <?php while( $toprow77 = sqlsrv_fetch_array( $stmt7) ) {

        echo  "<div class='parent-div'><span class='rank'>" . $toprow77['overallRank'] . "</span><span class='name'>" . $toprow77['EmployeeName'] . "</span><span class='points'>" . $toprow77['Total_points_Rewarded'] . "</span></div>";

      } ?>
       </mark>
      </li>

  </ol>

}   <?php  if ( $_SESSION['id'] == '100739')?> {
<ol>
<li>
<mark>
 <?php while( $toprow20 = sqlsrv_fetch_array( $stmt20) ) {

echo  "<div class='parent-div'><span class='rank'>" . $toprow20['overallRank'] . "</span><span class='name'>" . $toprow20['EmployeeName'] . "</span><span class='points'>" . $toprow20['Total_points_Rewarded'] . "</span></div>";

}?>

</mark>
</li>

</ol>
} <?php  if ( $_SESSION['id'] == '603')?> {
<ol>
<li>
<mark>
 <?php while( $toprow19 = sqlsrv_fetch_array( $stmt19) ) {

echo  "<div class='parent-div'><span class='rank'>" . $toprow19['overallRank'] . "</span><span class='name'>" . $toprow19['EmployeeName'] . "</span><span class='points'>" . $toprow19['Total_points_Rewarded'] . "</span></div>";

}?>

</mark>
</li>

</ol>
}

</div>
</div>

问题:当我运行上面的PHP时,它回显所有三个Employee_ids.It没有输入if else语句并选择employee_ID并仅显示已登录用户的信息。 登录用户的ID保存在我上面提到的第一个PHP代码段中。

我尝试过使用 - if,elseif,else

1 个答案:

答案 0 :(得分:0)

我有一个使用switch语句的解决方案,效果很好:

<div class="leaderboard">
  <?php switch ($_SESSION['id']) {
    case "1981":?>
  <ol>
    <li>
        <mark>
       <?php while( $toprow77 = sqlsrv_fetch_array( $stmt7) ) {

        echo  "<div class='parent-div'><span class='rank'>" . $toprow77['overallRank'] . "</span><span class='name'>" . $toprow77['EmployeeName'] . "</span><span class='points'>" . $toprow77['Total_points_Rewarded'] . "</span></div>";

      } ?>
       </mark>
      </li>

  </ol>

 <?php break;
  case "100739" : ?>
<ol>
<li>
<mark>
<?php while( $toprow20 = sqlsrv_fetch_array( $stmt20) ) {

echo  "<div class='parent-div'><span class='rank'>" . $toprow20['overallRank'] . "</span><span class='name'>" . $toprow20['EmployeeName'] . "</span><span class='points'>" . $toprow20['Total_points_Rewarded'] . "</span></div>";

}?>

</mark>
</li>

</ol>

<?php
 break;

}
?>



</div>