


How to generate online employee attendance report through PHP and Vue
In the modern office environment, managing employee attendance is a very important task. With the continuous development of technology, generating online employee attendance reports through automated systems has become a common requirement. This article will introduce how to use PHP and Vue to implement this function, and provide specific code examples.
- Preliminary preparation
Before starting, we need to ensure that the relevant environments of PHP and Vue have been installed on the server. If it is not installed, you can find the corresponding installation tutorial through the link below.
- PHP installation tutorial: https://www.php.net/manual/en/install.php
- Vue installation tutorial: https://vuejs .org/v2/guide/installation.html
- Create database table
Before generating the attendance report, we need to create a database table to store employee attendance records. You can use the following SQL statement to create a simple table structure.
CREATE TABLE `attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `employee_id` int(11) NOT NULL, `date` date NOT NULL, `clock_in_time` time NOT NULL, `clock_out_time` time NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
In this table, we store information related to each punch-in, including employee ID, date, work time and off work time, etc.
- Create PHP background file
We use PHP to handle background logic and read data from the database. First we need to create a file named "getAttendance.php" and write the following code:
<?php // 连接到数据库 $conn = new mysqli("localhost", "username", "password", "attendance"); // 检查连接是否成功 if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } // 查询数据库中的考勤记录 $sql = "SELECT * FROM attendance"; $result = $conn->query($sql); // 检查查询结果是否为空 if ($result->num_rows > 0) { // 将查询结果转换为JSON格式,并输出给前端 $rows = array(); while ($row = $result->fetch_assoc()) { $rows[] = $row; } echo json_encode($rows); } else { echo "没有找到考勤记录"; } // 关闭数据库连接 $conn->close();
In this file, we first connect to the database, and then query the attendance records in the database, And convert the result into JSON format and output it to the front end.
- Create Vue front-end code
Next we need to create a Vue front-end page to display attendance records. First create a file named "index.html" and introduce the Vue and axios libraries. Then write the following code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>员工考勤报告</title> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> </head> <body> <div id="app"> <table> <thead> <tr> <th>员工ID</th> <th>日期</th> <th>上班时间</th> <th>下班时间</th> </tr> </thead> <tbody v-if="attendance.length"> <tr v-for="record in attendance" :key="record.id"> <td>{{ record.employee_id }}</td> <td>{{ record.date }}</td> <td>{{ record.clock_in_time }}</td> <td>{{ record.clock_out_time }}</td> </tr> </tbody> <tbody v-else> <tr> <td colspan="4">没有找到考勤记录</td> </tr> </tbody> </table> </div> <script> new Vue({ el: '#app', data: { attendance: [] }, mounted() { this.getAttendance(); }, methods: { getAttendance() { axios.get('getAttendance.php') .then(response => { this.attendance = response.data; }) .catch(error => { console.log(error); }); } } }); </script> </body> </html>
In this code, we create a Vue instance and call the getAttendance method in the mounted hook function to obtain the attendance record. Then use the v-for directive to generate each row of the table.
- Run the project
Now we only need to place the above two files in the root directory of the server and access the "index.html" file in the browser to see the generated Online employee attendance reports.
Through the above steps, we successfully used PHP and Vue to generate an online employee attendance report. Of course, this is just a simple example and you can make more complex developments based on actual needs. Hope this article is helpful to you!
The above is the detailed content of How to generate online employee attendance report via PHP and Vue. For more information, please follow other related articles on the PHP Chinese website!

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
