Jump to content


Photo

Displaying articles in a particular order with PHP and MySQL


  • Please log in to reply
2 replies to this topic

#1 exeterdad

exeterdad
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 16 May 2006 - 03:06 AM

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.

#2 rburch

rburch
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 16 May 2006 - 05:16 AM

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\" /] .
"...there's a difference between knowing the path and walking the path." - The Matrix

#3 exeterdad

exeterdad
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 16 May 2006 - 01:54 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users