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; ?> <?=$title;?> - Game Collection

Game Collection

sys_id) || $system->sys_id !== $game->sys_id || (!$showAllGames && empty($headerPrinted))): $headerPrinted = true; if($showAllGames) { $getSystem->bindValue('sys', $game->sys_id); $getSystem->execute(); } if($showAllGames) { if(isset($system)): ?>
fetch(PDO::FETCH_OBJ); } ?>

sys_name;?>

sys_games_owned);?> of sys_games);?> gamesys_games !== 1 ? 's' : '');?>

game_title;?>

game_region;?>