-1

There is a function I'm using to get next photo in gallery:

$q = "SELECT i FROM GalleryModule\Image i WHERE i.id = (SELECT MIN(p.id) FROM GalleryModule\Image p WHERE p.id > :id ORDER BY p.position, p.id DESC) WHERE i.gallery = :gallery";
    $query = $this->getEntityManager()->createQuery($q);
    $query->setMaxResults(1);
    $query->setParameters(array(
        'id' => $image->getId(),
        'gallery' => $image->getGallery()->getId()
    ));
    return $query->getOneOrNullResult();

The error I'm still facing:

Doctrine\ORM\Query\QueryException

[Syntax Error] line 0, col 143: Error: Expected end of string, got 'WHERE'

Thanks a lot in advance.

peter.o
  • 3,460
  • 7
  • 51
  • 77

1 Answers1

3

You have multiple where's

Perhaps u mean this:

SELECT i FROM GalleryModule\Image i 
WHERE i.id = 
    (SELECT MIN(p.id) 
    FROM GalleryModule\Image p 
    WHERE p.id > :id ORDER BY p.position, p.id DESC) 
AND i.gallery = :gallery
Eernie
  • 470
  • 3
  • 15
  • Oh yes, you're absolutely right. Thanks a lot! I was trying to rewrite the query from DIBI fluent code and there was sth like `->where('query1')->where('query2')`. And it stands for `WHERE query1 AND query2` :) – peter.o Mar 27 '13 at 13:32