prepare(' SELECT s.*, ( SELECT COUNT(`game_id`) FROM `col_games` WHERE `sys_id` = s.`sys_id` ) AS `sys_games`, ( SELECT COUNT(`game_id`) FROM `col_games_ownership` WHERE `game_id` IN ( SELECT `game_id` FROM `col_games` WHERE `sys_id` = s.`sys_id` ) ) AS `sys_games_owned` FROM `col_systems` AS s WHERE `sys_id` = :sys '); if(!$showAllGames) { $getSystem->bindValue('sys', $sysId); $getSystem->execute(); $system = $getSystem->fetch(PDO::FETCH_OBJ); if(empty($system)) { http_response_code(404); die('No such system.'); } } $getGames = $pdo->prepare(sprintf( ' SELECT g.*, ( SELECT COUNT(`game_id`) > 0 FROM `col_games_ownership` WHERE `game_id` = g.`game_id` ) AS `game_owned` FROM `col_games` AS g %s ORDER BY %s`game_owned` DESC, g.`sys_id`, COALESCE(`game_title_order`, `game_title`) ', $showAllGames ? '' : 'WHERE `sys_id` = :sys', $showAllGames ? '( SELECT COUNT(`game_id`) FROM `col_games` WHERE `sys_id` = g.`sys_id` ) DESC, ' : '' )); if(!$showAllGames) $getGames->bindValue('sys', $sysId); $getGames->execute(); $games = $getGames->fetchAll(PDO::FETCH_OBJ); $title = $showAllGames ? 'All Games' : $system->sys_name; ?>
=number_format($system->sys_games_owned);?> of =number_format($system->sys_games);?> game=($system->sys_games !== 1 ? 's' : '');?>