+
+$prev = $DB->query('SELECT COUNT(id) FROM photos WHERE id<'.$id)->fetch_row(); #check if there are some previous photos
+$prev=$prev[0];
+if($prev>0) {
+$prev=$DB->query('SELECT * FROM photos WHERE id<'.$id.' ORDER BY id DESC LIMIT 1;')->fetch_assoc(); #if yes, get the previous photo's data
+?>
+
+
+}
+$next = $DB->query('SELECT COUNT(id) FROM photos WHERE id>'.$id)->fetch_row(); #check if there are some next photos
+$next=$next[0];
+if($next>0) {
+$next=$DB->query('SELECT * FROM photos WHERE id>'.$id.' ORDER BY id ASC LIMIT 1;')->fetch_assoc(); #if yes, get the next photo's data
+?>
+