Using EE v 1.6.8
When I click the “last page” link in my pagination, the page has no data returned. Every other paginated page shows results correctly. Basically, EE thinks there is 1 more page of results than there really is.
Here is the sql I’m using in my query tag:
SELECT DISTINCT member_id, avg, url_title, title, field_id_9, field_id_12,
field_id_13, field_id_14, field_id_21, field_id_24, field_id_46, field_id_47,
username, screen_name FROM exp_weblog_data JOIN exp_weblog_titles ON
exp_weblog_titles.entry_id = exp_weblog_data.entry_id JOIN exp_members ON
exp_members.member_id = exp_weblog_titles.author_id LEFT JOIN exp_rating_stats ON
exp_weblog_titles.entry_id = exp_rating_stats.entry_id WHERE exp_weblog_data.weblog_id = '1'
AND exp_weblog_titles.status = 'open' ORDER BY exp_weblog_titles.entry_date DESCI have found that the issue is the DISTINCT . When I remove DISTINCT, the last page has results. The thing is, I need the DISTINCT in my sql query or otherwise my results have duplicates due to the exp_ratings table (solspace rating module) having multiple records per entry_id.
So basically with DISTINCT in the query, results are as they should be, no duplicates, but EE is counting the total pages as though the DISTINCT isn’t there (so it thinks there are more results than there actually is), so the extra page is tacked on.
Just as a test thinking that maybe EE doesn’t like the DISTINCT where it is, I re-wrote the query as such which worked in phpMyAdmin:
SELECT member_id, url_title, title, field_id_9, field_id_12, field_id_13, field_id_14,
field_id_21, field_id_24, field_id_46, field_id_47, username, screen_name FROM
exp_weblog_data JOIN exp_weblog_titles ON exp_weblog_titles.entry_id =
exp_weblog_data.entry_id JOIN exp_members ON exp_members.member_id =
exp_weblog_titles.author_id LEFT JOIN (select distinct entry_id, avg from exp_rating_stats)
AS stats ON stats.entry_id = exp_weblog_titles.entry_id WHERE exp_weblog_data.weblog_id =
'1' AND exp_weblog_titles.status = 'open' ORDER BY exp_weblog_titles.entry_date DESCbut when EE ran this it throws the following error:
MySQL ERROR:
Error Number: 1054
Description: Unknown column 'stats.entry_id' in 'on clause'
Query: SELECT COUNT(*) AS count FROM exp_weblog_data JOIN exp_weblog_titles ON exp_weblog_titles.entry_id = exp_weblog_data.entry_id JOIN exp_members ON exp_members.member_id = exp_weblog_titles.author_id LEFT JOIN (SELECT COUNT(*) AS count FROM exp_rating_stats) AS stats ON stats.entry_id = exp_weblog_titles.entry_id WHERE exp_weblog_data.weblog_id = '1' AND exp_weblog_titles.status = 'open' ORDER BY exp_weblog_titles.entry_date DESCI’m out of ideas. I was hoping the re-written query might work. I’m not sure what to do now.
I think the handling of DISTINCT in the query module may be a EE bug.
Please help.