<?php
header("Connection: close");
Header("Cache-Control: no-cache, must-revalidate"); // говорим браузеру что-бы он не кешировал эту страницу
Header("Pragma: no-cache");
header("Content-type: application/json");
$array = array();
if (filter_has_var(INPUT_POST, 'id')) {
    $args = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT, ['options' => [
        'default' => 0,
        'min_range' => 0
    ]]);
    $array = (array)DB:: $pdo->query("SELECT s.`id` as code, s.`image`
        FROM `stickers_buy` as b
        INNER JOIN `stickers` as s ON s.id_cat = b.id_cat
        WHERE b.`id_cat` = ? AND b.`id_user` = ? AND b.`hide` = '0'
        ORDER BY s.`id` DESC", [$args, $user['id']])->fetchAll();
    if (in_array(false, $array, true)) $array = [];

} else {
    $array = (array)DB:: $pdo->query("SELECT b.id_cat, s.cover
        FROM `stickers_buy` as b
        INNER JOIN `stickers_cat` as s ON s.id = b.id_cat
        WHERE b.`id_user` = ? AND b.`hide` = '0'
        ORDER BY s.`id` DESC", [$user['id']])->fetchAll();
    if (in_array(false, $array, true)) $array = [];

}
echo json_encode($array);
exit();
?>