如何在getQuery中使用LIMIT


8

给定所需的SQL:

SELECT * FROM #__tablename LIMIT 5

如何使用$ query完成它?

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

Answers:


9

J2.5和3.x都将有所不同。

Joomla 2.5:

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

其中0在所述启动/偏移5极限

Joomla 3.x

$query->setLimit(5);

这也接受第二个参数,它是offset,但不是必需的

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.