How to develop a simple task manager using MySQL and JavaScript
Overview:
Task manager is a common application that can help us Organize and track completion of daily tasks. In this article, we will learn how to develop a simple task manager using MySQL and JavaScript. The manager will have the ability to add, edit, and delete tasks, as well as display and search functions for task lists. We will use MySQL as the database to store task information, and JavaScript to implement the front-end user interface and interact with the database.
Preparation:
Development Task Manager:
const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'task_manager' }); connection.connect((err) => { if (err) throw err; console.log('Connected to MySQL database'); });
function addTask(taskName, deadline, priority) { const task = { name: taskName, deadline: deadline, priority: priority }; connection.query('INSERT INTO tasks SET ?', task, (err, res) => { if (err) throw err; console.log('Task added successfully'); }); }
function editTask(taskId, updatedTask) { connection.query('UPDATE tasks SET ? WHERE id = ?', [updatedTask, taskId], (err, res) => { if (err) throw err; console.log('Task updated successfully'); }); }
function deleteTask(taskId) { connection.query('DELETE FROM tasks WHERE id = ?', taskId, (err, res) => { if (err) throw err; console.log('Task deleted successfully'); }); }
function displayTasks() { connection.query('SELECT * FROM tasks', (err, rows) => { if (err) throw err; console.log('Tasks:', rows); }); }
function searchTasks(keyword) { connection.query('SELECT * FROM tasks WHERE name LIKE ?', "%" + keyword + "%", (err, rows) => { if (err) throw err; console.log('Search results:', rows); }); }
Summary:
By using MySQL and JavaScript to develop the task manager, we can add, edit, and delete tasks, and can display the task list and search on the front-end interface Task-specific functionality. The above is a simple code example. You can modify and extend the code according to your own needs to achieve more functions and a better user experience. I hope this article can help you get started quickly and understand how to develop a task manager using MySQL and JavaScript.
The above is the detailed content of How to develop a simple task manager using MySQL and JavaScript. For more information, please follow other related articles on the PHP Chinese website!