我在joomla中实现分页。
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('c.*,cat.alias as catalias')
->from('#__content AS c')
->from('#__categories AS cat')
->where('c.catid=19','AND')
->where('c.state=1','AND')
->where('c.catid = cat.id')
->order('c.created '.' ASC');
$db->setQuery($query,0,5);
$results = $db->loadAssocList();
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pager= new JPagination($db->loadResult(), 0, 2);
foreach ($results as $res) {
echo $res['id'];
....
.....
}
echo $pager->getListFooter();
这将根据页数限制(3页中有6条记录(页数限制2)),在页脚显示页码(如123,带有超链接)。但所有记录都显示在一页中。而不是像每页中有两条记录。
这里需要什么变化。请帮我任何人。
提前谢谢
最佳答案
我找到了我问题的答案:
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$limit = $app->getUserStateFromRequest("$option.limit", 'limit', 2, 'int');
$limitstart = $app->input->get('limitstart', 0, 'INT');
$query = $db->getQuery(true)
->select('SQL_CALC_FOUND_ROWS c.*,cat.alias as catalias')
->from('#__content AS c')
->from('#__categories AS cat')
->where('c.catid=19','AND')
->where('c.state=1','AND')
->where('c.catid = cat.id')
->order('c.created '.' ASC');
$db->setQuery($query,$limitstart, $limit);
$results = $db->loadAssocList();
if(!empty($results)){
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pager= new JPagination($db->loadResult(), $limitstart, $limit);
foreach ($results as $res) {
echo $res['id'];
YOUR_CODE_HERE
}
echo $pager->getListFooter();
}
关于php - 如何在joomla中实现分页?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26990456/