Joomla Database - How to use LIMIT in getQuery?

前端 未结 4 1453
别跟我提以往
别跟我提以往 2021-02-04 02:42

I want to build the below query using joomla inbuilt database class.

SELECT * 
FROM table_name
ORDER BY id DESC
LIMIT 1

This is the query I hav

4条回答
  •  醉话见心
    2021-02-04 03:12

    Update: Just had to revisit this answer, and I can confirm, both the methods setLimit & order are working if used as below.

    $query->order($db->qn($data->sort_column_name) . ' ' . $data->sort_column_order);
    $query->setLimit($length,$start);
    

    OLD ANSWER

    As of 08/Sept/14 The solutions from @Dasun or @escopecz arent working for me on J3.x

    but this old trick is working for me which is nice,

      $query->order($db->qn('id') . ' DESC LIMIT 25');
    

    And About your specific requirement of wishing to fetch only 1 row you could use :

      $rows = $db->loadObject();
    

提交回复
热议问题