Jump to content

[SOLVED] Adding a sticky to a blog: Ordering where sticky = 1, then ordering by ID


imekul

Recommended Posts

I have a blog that displays the entries with a pretty simple query:

 

SELECT * FROM blog ORDER BY entrynumber DESC LIMIT 50

 

This works fine, and it sorts by the entry number, and thus, is in chronological order (latest post is shown first).  I'm wanting to add a sticky / announcement switch to each entry that will put that entry on top of all of the other ones, so it will basically stay on top, regardless of what its date or entrynumber is.

 

I'm thinking of adding a sticky field to the table, and then switching it to 1 on any post that I want stickified.  I can then access the stickies by using this:

 

SELECT * FROM blog WHERE sticky = 1

 

But I would like to essentially merge the two queries.  I'm not too familiar with SQL, but I understand that I should be able to have a query that will first select any post where sticky = 1 (and sort those by entrynumber, should there happen to be more than one sticky at a time).  After that, I would like it to simply sort the next 50 results by entrynumber.

 

Does anybody know how I can sort like this?  The idea seems pretty simple, but I'm not sure what the SQL would be.

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.