我已经建立了一个员工信息系统,他们可以申请休假并查看休假状态。问题是当员工想查看他的休假时,他可以看到所有申请休假的人。
下面是一个例子,登录的用户是jane smith,当我去查看我的叶子时,这是我看到的:
所以基本上我是根据用户的登录来显示休假的。另外,我的系统中有两个表,employee和leaves。
员工表:
离开表:
我有一个我为我的员工信息系统做的会话代码。我想我需要加入我的会话代码和查看我的离开代码来回答我的问题。问题是,我不知道如何把两者结合起来。
下面是我为员工信息系统编写的会话代码:
<?php
session_start();
ob_start();
//Include the database connection file
include "database_connection.php";
//Check to be sure that a valid session has been created
if(isset($_SESSION["VALID_USER_ID"]))
{
//Check the database table for the logged in user information
$check_user_details = mysql_query("select * from `employee` where `username` = '".mysql_real_escape_string($_SESSION["VALID_USER_ID"])."'");
//Validate created session
if(mysql_num_rows($check_user_details) < 1)
{
session_unset();
session_destroy();
header("location: login.php");
}
else
{
//Get all the logged in user information from the database users table
$get_user_details = mysql_fetch_array($check_user_details);
$user_id = strip_tags($get_user_details['id']);
$fullname = strip_tags($get_user_details['fullname']);
$username = strip_tags($get_user_details['username']);
$email = strip_tags($get_user_details['email']);
$address = strip_tags($get_user_details['address']);
$gender = strip_tags($get_user_details['gender']);
$contact = strip_tags($get_user_details['contact']);
$user_access_level = strip_tags($get_user_details['user_levels']);
$passwd = strip_tags($get_user_details['password']);
$picture = strip_tags($get_user_details['picture']);
$sickleave = strip_tags($get_user_details['sickleave']);
$vacationleave = strip_tags($get_user_details['vacationleave']);
?>
这是我的观点我的休假代码:
<div class="container">
<div class="page-header">
<h3>My Leaves</h3>
<div class="table-responsive">
<table class="table">
<tr>
<th>Employee Name</th>
<th>Phone</th>
<th>Email</th>
<th>From</th>
<th>To</th>
<th>Reason</th>
<th>Status</th>
</tr>
<?php
include ('database.php');
$result = $database->prepare ("SELECT * FROM leaves order by leaveno DESC");
$result ->execute();
for ($count=0; $row_message = $result ->fetch(); $count++){
?>
<tr>
<td><?php echo $row_message['full_name']; ?></td>
<td><?php echo $row_message['phone']; ?></td>
<td><?php echo $row_message['email']; ?></td>
<td><?php echo $row_message['fromdate']; ?></td>
<td><?php echo $row_message['todate']; ?></td>
<td><?php echo $row_message['reason']; ?></td>
<td><?php echo $row_message['status']; ?></td>
</tr>
<?php } ?>
</table>
<a href="home"><button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-arrow-left"></i> Back</button></a>
</div>
</div>
</div>
</div>
</div>
所以正如我所说,我不知道该如何合并这两个代码。我知道有很多教程,但我真的很难理解它们。
另外,我知道会话代码中的mysql已被弃用。我有计划在将来改变他们。同时我得想办法。任何帮助都将不胜感激。
最佳答案
由于您正在会话变量$_SESSION["VALID_USER_ID"]
中存储已登录用户的用户名,因此可以使用它直到会话处于活动状态。您可以在左视图代码中使用它。
在离开视图代码时,请使用以下代码:
$stmt = $conn->prepare("SELECT leaves.* FROM leaves INNER JOIN employee ON employee.id = leaves.user_id WHERE employee.username = ?");
$stmt->bind_param("s", $_SESSION["VALID_USER_ID"]);
这样,您将获得用户名
$_SESSION["VALID_USER_ID"]
的用户的所有休假申请。关于php - 查看休假详细信息,取决于登录的用户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48353864/