Querrying photos from the database