0

I'm writing a simple forum system to go along with one of my projects - nothing fancy, just categories, forums, threads, and posts. Some threads, however, are marked as 'stick', which means that they're stickies. No matter how many threads there are or where they're posted on, they always must appear at the top of the forum. However, the other threads are paginated.
I've tried using the following mysql query to select 20 normal threads and all stickies, but it doesn't work. Is there a way to get around this in the actual query, or should I resort to using multiple queries in the PHP to get the other threads?

SELECT * FROM `threads` WHERE `forumid` = 1 AND (`status` = 'none' LIMIT 20) OR (`status` = 'stick')

Thanks! (This is in the PHP forum as I'm not sure if the solution is in PHP or MySQL)

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Arianna
1

(This is in the PHP forum as I'm not sure if the solution is in PHP or MySQL)

It's MySQL, but no problem :)
How about using an union?

SELECT * FROM `threads` WHERE `forumid` = 1 AND `status` = 'stick'
UNION
SELECT * FROM `threads` WHERE `forumid` = 1 AND `status` = 'none' LIMIT 20
0

Thank you! :D That really helped me! :) I have this worked out now. Thanks again for helping me. x3

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.