AndrewSimm
Well-known member
I have been trouble using fetchAllKeyed and getting pagination to work. The problem is I don't have a finder to get total from/
Here is the start of my code, and this works fine.
Here is the only one I know to get total.
I imagine I should be doing this a different way. What am I missing?
Here is the start of my code, and this works fine.
PHP:
$page = $this->filterPage();
$perPage = 40;
$offset = ($page - 1) * $perPage;
$db = \XF::db();
$values = $db->fetchAllKeyed("select xf_user.user_id, xf_user.username, xf_user.message_count, xf_user.warning_points, sum(xf_report.report_count) as report_count
from xf_user
inner join xf_report on xf_user.user_id = xf_report.content_user_id
group by xf_user.user_id, xf_user.username, xf_user.message_count, xf_user.warning_points
having sum(xf_report.report_id) > 0
order by report_count DESC
limit ?,?", 'user_id', [$offset, $perPage]);
Here is the only one I know to get total.
PHP:
$total = $db->fetchAll("select xf_user.user_id, xf_user.username, xf_user.message_count, xf_user.warning_points, sum(xf_report.report_count) as report_count
from xf_user
inner join xf_report on xf_user.user_id = xf_report.content_user_id
group by xf_user.user_id, xf_user.username, xf_user.message_count, xf_user.warning_points
having sum(xf_report.report_id) > 0
order by report_count DESC");
$users = \XF::em()->findByIds('XF:User', array_keys($values));
$users = $users->sortByList(array_keys($values));
$total = count($total);
I imagine I should be doing this a different way. What am I missing?