sniperscope Posted May 23, 2012 Share Posted May 23, 2012 Hello I have two type of records in my MySQL database gradeA and gradeB How can i display gradeB records at very last page of pagination. Let me make myself clear with an example: Let's say i have 20 records 12 of them is gradeA and 8 of them is gradeB I want to display 5 records each page so, Page #1 Page #2 Page #3 Page #4 Page #5 gradeA gradeA gradeA gradeB gradeB gradeA gradeA gradeA gradeB gradeB gradeA gradeA gradeB gradeB gradeB gradeA gradeA gradeB gradeB gradeB gradeA gradeA gradeB gradeB gradeB I am using following mysql query but it brings me wrong order. $trm = EscapeStr($_GET['shopWord']); $sql = "SELECT s.id, s.s_name, s.s_type, s.s_area, s.d_area, s.grade, e.news_title, e.news, e.news_icon, cp.c_date FROM (SELECT id, s_name, s_type, s_area, d_area, grade FROM s_master WHERE s_area LIKE '%kansai%' AND is_active = 'yes') AS s LEFT JOIN (SELECT s_id, news_id, news_title, MAX(news_date) AS news, news_icon FROM news_event GROUP BY s_id ORDER BY news_id DESC) e ON s.id = e.shop_id LEFT JOIN coupon cp ON s.id = cp.s_id WHERE s.s_name LIKE'%" .$trm. "%' GROUP BY s.id ORDER BY e.news DESC, s.grade ASC"; $sql_actual = mysql_query($sql); Above query gives me Page #1 Page #2 Page #3 Page #4 Page #5 gradeA gradeA gradeA gradeA gradeB gradeA gradeA gradeA gradeA gradeB gradeA gradeA gradeA gradeA gradeB gradeB gradeB gradeB gradeB gradeB gradeB gradeB gradeB gradeB gradeB Quote Link to comment Share on other sites More sharing options...
Illusion Posted May 23, 2012 Share Posted May 23, 2012 Change ORDER BY e.news DESC,s.grade ASC to ORDER BY s.grade ASC, e.news DESC Quote Link to comment Share on other sites More sharing options...
sniperscope Posted May 23, 2012 Author Share Posted May 23, 2012 Change ORDER BY e.news DESC,s.grade ASC to ORDER BY s.grade ASC, e.news DESC No hope. Still same. Quote Link to comment Share on other sites More sharing options...
Illusion Posted May 23, 2012 Share Posted May 23, 2012 The result set order shouldn't be same when we flip the positions in order by clause unless the columns are in one-to-one mapping. Quote Link to comment Share on other sites More sharing options...
sniperscope Posted May 25, 2012 Author Share Posted May 25, 2012 Illusion thanks for help. The solution was as you said. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.