Why is my chained setLimit not working?

34 views
Skip to first unread message

Rene Kreijveld

unread,
Jul 25, 2017, 5:35:51 AM7/25/17
to Joomla! General Development
I have a database query with a LIMIT and I found out dat chaining the limit clause does not work.

This works:

$query = $db->getQuery(true)
   
->select($db->quoteName('legingsdag'))
   
->from($db->quoteName('#__containerwissel_wisseldag'))
   
->where($db->quoteName('route') . ' = ' . $route)
   
->where($db->quoteName('legingsdag') . ' > "' . $vandaag . '"')
   
->order($db->quoteName('legingsdag') . ' ASC');
$query
->setLimit(1);

But this does not:

$query = $db->getQuery(true)
   
->select($db->quoteName('legingsdag'))
   
->from($db->quoteName('#__containerwissel_wisseldag'))
   
->where($db->quoteName('route') . ' = ' . $route)
   
->where($db->quoteName('legingsdag') . ' > "' . $vandaag . '"')
   
->order($db->quoteName('legingsdag') . ' ASC')
   
->setLimit(1);

Can someone explain why the second one doesn't work? (returns empty result) ...

Todor Iliev

unread,
Jul 25, 2017, 11:45:37 AM7/25/17
to Joomla! General Development
Could you post the result of the query builder, please?

Let we see what are the results of both queries.

You can build the queries, displaying the $query object as a string.

echo (string)$query;

Rene Kreijveld

unread,
Jul 26, 2017, 2:33:42 AM7/26/17
to Joomla! General Development
The first one with $query->setLimit(1); gives me:

SELECT `legingsdag` FROM `#__containerwissel_wisseldag` WHERE `route` = 6 AND `legingsdag` > "2017-07-26" ORDER BY `legingsdag` ASC

The second one with ->setLimit(1); gives me an empty string.

Strangely the result of the first one does not include the limt ...
Message has been deleted

Rene Kreijveld

unread,
Jul 26, 2017, 3:28:26 AM7/26/17
to Joomla! General Development
Arch ... forget I posted this ... This was on Joomla 2.5 website, that doesn't even have setLimit.
Reply all
Reply to author
Forward
0 new messages