Let's assume each thread in your database contains the following fields:
DateCreated
The date and time the thread was created. Populated when you create a new thread in the database.
DateLastPost
The date and time the thread was last posted to. Populated with a new value each time a new post is added to the database.
ThreadType
The type of thread, "sticky" or "normal"
ForumID
The ID number of the forum the thread belongs to
Using multiple queries and the values above, you can order your threads like you want to:
// "sticky" query
"SELECT * FROM threads WHERE ForumID = $ForumID AND ThreadType = "sticky" ORDER BY DateCreated";
// "normal" query
"SELECT * FROM threads WHERE ForumID = $ForumID AND ThreadType = "normal" ORDER BY DateLastPost";
You can consolidate these queries into one with almost the same success. All you would need to do is change your ThreadType to be numeric, with "sticky" threads having a higher value than "normal" threads. Give a "sticky" thread a value of 1, and "normal" a value of 0.
Your query would look like this:
// all theads query
"SELECT * FROM threads WHERE ForumID = $ForumID ORDER BY ThreadType DESC, DateLastPost DESC";
With this query your threads will be first sorted with "sticky" threads first followed by the "normal" threads. However,
the drawback is that each group of threads will be ordered by the last time they were posted to.