Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP to sort order of database records

Status
Not open for further replies.

sdh

Programmer
Apr 30, 2001
121
0
0
GB
I am writing a CMS system I have been puzzling over this for a few days and not getting anywhere.

I have a table which has a column content_order
this holds an integer which dictates the order of paticular content articles.

I have an interface which lists the articles

I want to add functionality to allow the user to move articles up or down the content order

Can anyone offer any pointers

I guess I need to use update statements to change the content order but am a bit baffled

Any help would be appreciated

 
the answer is you add another column to your database called contentorder and then sort by that.

in order to give your users the ability to select the order in a neat way, i too have pondered this for some time. in the end i now always use variations on a drag and drop javascript theme. sometimes with sajax interaction. start with tool-man.org i believe that will solve your problem. post back if you have issues integrating the code.
 
Thanks

jpadie

I will check out tool-man.org

Shaun
 
I did something very similar in my code, and for the JS frontend I used (and customized for my needs) a file called sort.js available at
If you want more info about how I interacted with the database, let me know. But basically, I filled the <select> based on the order already there, and after they reordered, I updated the database accordingly. In my case it's more complex than just changing the order field values, because a user could remove items from the list, duplicate items (it's a database of songs and this table keeps songlists for events, so doing a song more than once is not out of the question), or even replace the whole set with different songs (calling the page from a different place), so after they have played with the sorting screen and clicked OK, I completely delete the old records and insert the set of new ones. But in your case you might be able to just step through the records with UPDATE statements to just change the value of content_order. (Warning, though: if content_order is part of your primary key, you'll need to first change them all to something that won't be a duplicate, like zero perhaps, and then go through again and set the new values - otherwise you might hit a duplicate key error as you go along.)
 
Hi,

I once made a custom CMS with sorting..
For sorting, I used a 3 digit integer.

eg. All pages added originally, where 100, 200, 300, etc.

Then, you could give one integer of 150, it would land in the middle of 100 and 200..

you could change 200 to 350..

etc. It would then sort on the field, as suggested above. (serverside)

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top