this should do it
<?php
/**
* API Request: GET - List Games
* JSON Endpoint: /api/public/v1/list_Games.json
* @Params: ? $limit, $order_by, $sort_by
*/
if (array_key_exists('list_Games', $_GET)) {
$data = $db->query_params('SELECT DISTINCT torrent_id, info_hash, name, descr AS description, cover1 AS boxart, image1 AS screen_1, image2 AS screen_2, category, size, added, comments, views, hits, times_completed AS completed, leechers, seeders, numratings AS total_ratings, external, tags, youtube, version, dlc FROM torrents ORDER BY :eek:rder_by :sort_by LIMIT :limit',
array(
'order_by' => strval($_GET['order_by']) ? strval($_GET['order_by']) : 'added', // Order By - Default: added
'sort_by' => strval($_GET['sort_by']) ? strval($_GET['sort_by']) : 'DESC', // Sort By - Default: DESC
'limit' => intval($_GET['limit']) ? intval($_GET['limit']) : 20) // Limit - Default: 20
);
$gameData = array();
if ($data) {
$listgames = $data->fetchAll();
$status = ($data) ? 'ok' : 'error';
$limit = 0;
foreach ($listgames as $row => $data) {
$limit++;
$data = $row;
$message = '';
if ($data) {
$message = 'Query was successful';
} else {
$message = 'Query returned error';
}
array_push($gameData, $listgames);
}
}
echo json_encode([
'status' => $status,
'status_message' => $message,
'data' =>
[
'game_count' => 958,
'limit' => $limit,
'page_number' => 1,
'games' => json_encode($listgames, JSON_PRETTY_PRINT, JSON_INVALID_UTF8_SUBSTITUTE)
]
]);
die();
}
/**
* API Request: GET - Game Details
* JSON Endpoint: /api/public/v1/Game_details.json
* @Params: $torrent_id
*/
if (array_key_exists('Game_details', $_GET)) {
$data = $db->query_params('SELECT torrent_id, info_hash, name, descr AS description, cover1 AS boxart, image1 AS screen_1, image2 AS screen_2, category, size, added, comments, views, hits, times_completed AS completed, leechers, seeders, numratings AS total_ratings, external, tags, youtube, version, dlc FROM torrents WHERE torrent_id = :torrent_id LIMIT 1',
array(
'torrent_id' => intval($_GET['torrent_id']) ? intval($_GET['torrent_id']) : 1) // Torrent ID - Default: 1
);
$gameData = array();
if ($data) {
$listdetails = $data->fetchAll();
$status = ($data) ? 'ok' : 'error';
foreach ($listdetails as $row => $data) {
$data = $row;
$message = '';
if ($data) {
$message = 'Query was successful';
} else {
$message = 'Query returned error';
}
array_push($gameData, $listdetails);
}
}
echo json_encode(
[
'status' => $status, '
status_message' => $message,
'data' => json_encode($listdetails, JSON_PRETTY_PRINT, JSON_INVALID_UTF8_SUBSTITUTE)
]);
}