Jump to content


This topic is now archived and is closed to further replies.


Displaying articles in a particular order with PHP and MySQL

Recommended Posts

I don't even have a clue how to go about this.

Basically I'm creating a PHP/MySQL site from the ground up. One because I want to understand everything that is going on with the code so I will be able to work on it. I guess I'm making a lite CMS.

I have a nice template made, a "backend" so I can write/edit/delete "articles". And many other useful features created.

But what I can't figure out, is how to make each article appear in a particular order.

I don't know if this is something that is done purely with MySQL or what? I'm not talking about sorting acsending or decending, or by the date. I need to assign a order to the articles, and when I decide that another article should be shown up higher on the list, how will the order of the other articles be updated?

I'm not looking for someone to write me the code. But I can't figure out what keywords to Google with to find the answer for myself.

Any insight would be greatly appreciated.

Share this post

Link to post
Share on other sites
The easy way to do this is by date, but if you don't want to do it that way...

The only other way to do this, that I can think of, is to place them in an order by reference number, then when you add a new article, your script adds +1 to each reference number - bumping each one down in the list of ordered articles [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] .

Share this post

Link to post
Share on other sites
So your suggesting that I add another colum to my articles table and name it something like "appearance", assign each article a "appearance number"

Then when I add or edit another article and want it to appear in let's say the 5th slot, I have a function increment each "appearance number" in the table greater than 5?

Then have a function that does the exact opposite when that article is deleted?

Then when my script displays the article, it sorts them ascending using the numbers from my new "appearance" colum?

BTW I'm really thankful for your input.

Share this post

Link to post
Share on other sites


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.