<?php

require_once '../include/DatabaseConn.php';

$db = new DatabaseConn();
$link = $db->connect();

$id = filter_input(INPUT_GET, "id",FILTER_VALIDATE_INT);

if($id == 0) {
    $res = mysqli_query($link, "select id, `link`,title,label,seen from notifications  order by id desc limit 5 ");
}
else if($id > 1) {
    $res = mysqli_query($link, "select id, `link`,title,label,seen from notifications where `id` < $id  order by id desc limit 5 ");
}

$std = new stdClass();
$std->lists = [];

if (mysqli_num_rows($res) == 0) {
    header("content-type: application/json");
    echo (json_encode($std));
    die();
}

while ($row = mysqli_fetch_object($res)) {
    array_push($std->lists, $row);
}
header("content-type: application/json");
echo (json_encode($std));
die();
