PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- Create the Users table CREATE TABLE Users ( uid INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL ); -- Insert sample data into Users INSERT INTO Users (email, name) VALUES ('alice@example.com', 'Alice'), ('bob@example.com', 'Bob'), ('charlie@example.com', 'Charlie');
Copy Clear
Copy Format Clear
<?php // SQL query to select data from Users $query = "SELECT email, uid, name FROM Users;"; // Execute the query using PDO $stmt = $pdo->prepare($query); $stmt->execute(); // Fetch all results $users = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html> <head> <title>User List</title> </head> <body> <h1>List of Users</h1> <?php foreach ($users as $user): ?> <p>User ID: <?= htmlspecialchars($user['uid']); ?>, Name: <?= htmlspecialchars($user['name']); ?>, Email: <?= htmlspecialchars($user['email']); ?></p> <?php endforeach; ?> </body> </html>
Show:  
Copy Clear