prepare("SELECT * FROM media WHERE id = :id"); $query->bindValue(":id", intval($_GET['id'])); $result = $query->execute(); if ($result) { $row = $result->fetchArray(SQLITE3_ASSOC); echo(json_encode($row)); } } else if (isset($_GET['filter']) && trim($_GET['filter']) !== "") { // get info about a subset of media files $query = $db->prepare("SELECT * FROM media m JOIN media_tags mt ON m.id = mt.media_id JOIN tags t ON mt.tag_id = t.id WHERE m.title LIKE :filter OR m.description LIKE :filter OR t.tag LIKE :filter ORDER BY m.id DESC"); $query->bindValue(":filter", "%" . $_GET['filter'] . "%"); error_log($query->getSQL(true)); $result = $query->execute(); if ($result) { $rows = array(); while ($res = $result->fetchArray(SQLITE3_ASSOC)) { $rows[] = $res; } echo(json_encode($rows)); } else { error_log($db->lastErrorMsg()); } } else { // get info about all media files $query = "SELECT * FROM media ORDER BY id DESC"; $result = $db->query($query); if ($result) { $rows = array(); while ($res = $result->fetchArray(SQLITE3_ASSOC)) { $rows[] = $res; } } echo(json_encode($rows)); } ?>