Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Neither union nor group by will help you here.
As far as I know, you cannot order in a sequential way like this, directly from a query.
Your best bet would be to process this not in a db, but in a server side language.
Having an array of normal posts, an array of sticky posts, and inserting a sticky between 2 regular during a loop over the regular posts.
You could do that in the db, by using 2 cursors too.
But, as the mysql documentation state, cursor are only allowed into stored procedure or functions.
http://dev.mysql.com/doc/refman/5.0/en/cursors.html
So, if you really really want to do that in the db, you'll have to create an stored procedure and call it rather than sending a complete query.
The logic of the SP would be (in my opinion):
Code:
set regular_cnt = 0
set sticky_cnt=0
open cursor_regular on regular posts
open cursor_sticky on sticky posts
while not end of cursor_regular:
if modulo(regular_cnt,6)==0 and regular_cnt>0: --not the first regular, but multiple of 7
fetch next sticky from cursor_sticky
set sticky_cnt+=1
fetch next regular from cursor_regular
set regular_cnt+=1
end while
__________________
Only a biker knows why a dog sticks his head out the window.
|