8

Given the desired SQL:

SELECT * FROM #__tablename LIMIT 5

How do I use $query to accomplish it?

$db = JFactory::getDBO();       
$query = $db->getQuery(true);
$query->select($db->nameQuote('*'));
$query->from($db->nameQuote('#__tablename'));      
$db->setQuery($query);      
$rows = $db->loadObjectList();
9

Both J2.5 and 3.x will vary.

Joomla 2.5:

$db->setQuery($query, 0, 5); 

where 0 is the start/offset and 5 is the limit

Joomla 3.x

$query->setLimit(5);

This also accepts a 2nd argument which is the offset, but is not required

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.