Luxury, Must Have List, To-Do List in PHP and SQLITE
Make sure the following things are included in your luxuries list:
1. Alive and Life itself
2. Loving
3. To Be Loved
1. Alive and Life itself
2. Loving
3. To Be Loved
Here is a sample PHP script using SQLite to create a simple to-do list application:
php
php
<?php
// Connect to SQLite database
$db = new SQLite3('todo.db');
// Create table to store to-do items
$db->exec("CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, task TEXT, status INTEGER)");
// Check if form was submitted
if (isset($_POST['add'])) {
$task = $_POST['task'];
// Insert new task into database
$db->exec("INSERT INTO todos (task, status) VALUES ('$task', 0)");
}
// Check if "complete" button was clicked
if (isset($_GET['complete'])) {
$id = $_GET['complete'];
// Update task status in database
$db->exec("UPDATE todos SET status = 1 WHERE id = $id");
}
// Get all to-do items from database
$result = $db->query("SELECT * FROM todos");
?>
<!DOCTYPE html>
<html>
<head>
<title>To-Do List</title>
</head>
<body>
<h1>To-Do List</h1>
<form action="" method="post">
<input type="text" name="task">
<input type="submit" name="add" value="Add Task">
</form>
<table>
<tr>
<th>Task</th>
<th>Status</th>
</tr>
<?php while ($row = $result->fetchArray()): ?>
<tr>
<td><?= $row['task'] ?></td>
<td>
<?php if ($row['status'] == 0): ?>
<a href="?complete=<?= $row['id'] ?>">Complete</a>
<?php else: ?>
Completed
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
</table>
</body>
</html>
This script uses an HTML form to allow the user to add new to-do items, and a table to display the current list of items. When the user submits the form, a new task is inserted into the todos table in the SQLite database. When the user clicks the "complete" link next to a task, the corresponding task's status is updated in the database. The list of to-do items is retrieved from the database and displayed in the table.
Comments