【问题标题】:sort table records in descending order - symfony按降序对表记录进行排序 - symfony
【发布时间】:2018-06-21 06:53:03
【问题描述】:

我在数据库中有一个记录表,其中最后插​​入的记录是表记录行中的最后一个记录。在我的 symfony 应用程序中,我有一个 sn-p 从数据库中获取数据,但最后插入的记录是迭代结果时视图中的最后一个记录。这是sn-p

已编辑

$restresults = $this->getDoctrine()->getRepository('myBundle:Images')->findAll();

如何按降序对上述原则 sn-p 进行排序,最后插入的成为第一条记录。

【问题讨论】:

    标签: php mysql symfony


    【解决方案1】:

    假设你有 id 列

    $restresults = $this->getDoctrine()->getRepository('myBundle:Images')->findBy([], ['id' => 'DESC']);
    

    【讨论】:

      【解决方案2】:

      第二个参数是订单:

      $messages = $em->getRepository("myBundle:Comments")->findBy(
          array(
              "imagefk" => $image
          ),
          array('id' => 'DESC')
      );
      
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      相关资源
      最近更新 更多