您好,我使用 Symfony2 和 Doctrine。
我想按照我的自定义订单和学说来订购
SELECT id_product, pro_name FROM product ORDER BY FIELD(id_product,3,5,2)
我努力了
$rang_1=array(3,5,2);
$products = $em->getRepository('CompanyMyBundle:Product')->findBy(array('public' => 1,'idProduct'=>$rang_1), array('idProduct'=>$rang_1), 5);
和
$sql = $em->createQuery("SELECT p FROM CompanyMyBundle:Product p WHERE l.public = 1 AND l.idProduct IN (".implode(',',$rang_1).") ORDER BY FIELD(l.idProduct,".implode(',',$rang_1).")")->setMaxResults(5);
有什么建议吗?