views:

50

answers:

1

Hi I am working on a mysql/php forum app as part of a corporate intranet system. My problem is that while listing all threads under a particular forum, there could be more than one "sticky threads" which should show on top and the rest should after them sorted by date in descending order. Just need to get an idea about the sql query to use. The tables are usual like 1. forums (with parent child relation to keep category and forums in one table only) 2. forum threads 3. thread replies

Thanks in advance for your help.

+3  A: 

Generally it's just an extra field in the database, a bit field, unless you need multiple types of stickies. Then you sort based on that field before you sort by date/subject/author.

SELECT ...
FROM posts
WHERE ...
ORDER BY (sticky = 1) DESC, ...

If you've got pageinated posts and want the stickies to show up on every page, not just the first one, then it's a bit more complex, but this should get you started.

Marc B