Return a default value if single row is not found

One way to do it SELECT IFNULL(MIN(`file`), ‘default.webm’) `file` FROM `show`, `schedule` WHERE `channel` = 1 AND `start_time` <= UNIX_TIMESTAMP() AND `start_time` > UNIX_TIMESTAMP()-1800 AND `show`.`id` = `schedule`.`file` ORDER BY `start_time` DESC LIMIT 1 Since you return only one row, you can use an aggregate function, in that case MIN(), that ensures that you’ll get … Read more

How to load local script files as fallback in cases where CDN are blocked/unavailable? [duplicate]

To confirm that cdn script loaded you can check for existence any variable/function this script defines, if it is undefined – then cdn failed and you need to load local script copy. On this principle are based solutions like that: <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”></script> <script>window.jQuery || document.write(‘<script src=”js/libs/jquery-1.5.1.min.js”>\x3C/script>’)</script> (if there is no window.jQuery property defined cdn script … Read more