V
V
Viktor Yanyshev2016-12-10 23:10:30
PHP
Viktor Yanyshev, 2016-12-10 23:10:30

How to display the employee's working hours in the time sheet, according to the date?

Tell me how to show the hours worked by an employee in the time sheet, in accordance with the date of the cell? The flight of fancy at this stage has completely turned off and I can’t find a solution how to show the data so that it was in accordance with Employee <=> Date <=> number of hours.
Now there is a database with 2 tables:

  • users - where is all the info on users
  • working_time - where id_user, wrk_date, wrk_time (id, yyyy-mm-dd, hh)

And also the table itself:
<table>
    <tr>
        <th>№</th>
        <th>Фамилия</th>
        <th>Имя</th>
        <!-- Числа -->
        <? foreach($calendar->getMonth() as $workDay):?>
            <th><?= $workDay; ?></th>
        <? endforeach; ?>
        <!-- Числа -->
    </tr>
    <!-- Вывод всех пользователей -->
    <? for($i = 0; count($usersList) > $i; $i++): ?>
        <tr>
            <td><?= $usersList[$i]['id']; ?></td>
            <td><?= $usersList[$i]['last_name']; ?></td>
            <td><?= $usersList[$i]['first_name']; ?></td>
        <!-- Рабочие часы -->
            <? foreach($calendar->getMonth() as $workDay):?>
                <td><!-- рабочие часы или кнопка на запись--></td>
            <? endforeach; ?>
        <!-- Рабочие часы -->
        </tr>
    <? endfor; ?>
    <!-- Вывод всех пользователей -->
</table>

Visualization:
b6403a65d88a4600867969fcc4adecbb.jpg
Now there are 2 functions that allow you to get data from the database. The first returns working hours for all employees (no date limit so far):
public function getAllUserWorkTime(){
        $db = Db::getConnect();
        $sql = "SELECT id_user,wrk_date,wrk_time FROM working_time";
        $result = $db->query($sql);

        $list = [];
        $i = 0;

        while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
            $list[$i]['id'] = $row['id_user'];
            $list[$i]['wrk_date'] = $row['wrk_date'];
            $list[$i]['wrk_time'] = $row['wrk_time'];
            $i++;
        }

        return $list;

    }

And all records of working hours for 1 employee:
public function getUserWorkTime($id){
        $db = Db::getConnect();
        $sql = "SELECT wrk_time FROM working_time WHERE id_user = $id";
        $result = $db->query($sql);

        $list = [];
        $i = 0;

        while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
            $list[$i] = $row['wrk_time'];
            $i++;
        }

        return $list;

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2016-12-11
@dimonchik2013

reflect as in the table - one number in one cell

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question