PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
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')
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']);
Show:  
Copy Clear