Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE shows (weekday int, start_at time, show_name varchar(64)); INSERT INTO shows VALUES (1, '08:00', 'The Breakfast Show'), (1, '10:00', 'The Fred and Lucy Hour'), (7, '06:00', 'The Hymn Hour')

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $weekday = date('N'); $hour = date('H:i'); $now_plaing = 'Default show'; $query = "SELECT show_name FROM shows WHERE weekday = ? AND start_at <= ? ORDER BY start_at DESC LIMIT 1;"; $stmt = $pdo->prepare($query); $stmt->execute([$weekday, $hour]); $show = $stmt->fetch(PDO::FETCH_ASSOC); printf("Now at %s playing: %s", $hour, $show['show_name']);
Copy Clear