I've made an employee information system where they can apply for a leave and view their leave status. The problem is when the employee wants to view his leave, he can see everyone who applied for a leave.

Here's an example, the user logged in is Jane Smith and when I go to view my leaves, this is what I see:

[![view leave](https://i.stack.imgur.com/xBwMo.png)](https://i.stack.imgur.com/xBwMo.png)

So basically I'm trying to display the leave based on the user logged in. Also I do have two tables in my system, employee and leaves.

**Employee Table:**
[![Employee Table](https://i.stack.imgur.com/y91L4.png)](https://i.stack.imgur.com/y91L4.png)

**Leaves Table:**
[![Leaves Table](https://i.stack.imgur.com/9z9Qc.png)](https://i.stack.imgur.com/9z9Qc.png)

I have a session code I did for my Employee Information System. I think I'm gonna need to join my session code and my view my leaves code to answer my question. The thing is, I don't know how I would incorporate the two.

So here's my session code I did for my Employee Information System:

```
<?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']);
?>

```

And here's my view my leave code:

```
<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>

```

So as I've said I don't know how i'd incorporate the two codes. I know there are tons of tutorial out there but I'm really having a hard time understanding them.

Also I know that mysql in the session code is deprecated. I have plans of changing them in the future. For the mean time i'd have to figure out how to do this. Any help would be appreciated.