Forum Moderators: coopster

Message Too Old, No Replies

Order by and setting weight of entries

Order by and setting weight of entries

         

drooh

6:59 am on Apr 4, 2008 (gmt 0)

10+ Year Member



Say I have information stored in my database for an mp3 player. The fields are artist, title, album, image, mp3, url and weight. Now I can use php to update an xml file that is read by flash for the playlist.

But what about changing the order of the tracks.

What is the best method for approaching this? I've heard of using "weights" to order by, but my question is how and what does that look like on the code level.

What do the sql queries look like. What do others do in this instance?

Say for instance I have

artist ¦ title ¦ album ¦ image ¦ mp3 ¦ url ¦ weight
bob ¦ rock me ¦ live ¦ pic3.jpg ¦ rockme.mp3 ¦ url ¦ 3
bob ¦ blues e ¦ live ¦ pic1.jpg ¦ bluesy.mp3 ¦ url ¦ 1
bob ¦ push up ¦ live ¦ pic2.jpg ¦ puchup.mp3 ¦ url ¦ 2

mikhaill

7:26 am on Apr 4, 2008 (gmt 0)

10+ Year Member



Select * from table order by weight desc; if you want it descending order.

Select * from table order by weight asc; if you want it in ascending order.

drooh

9:23 am on Apr 4, 2008 (gmt 0)

10+ Year Member



Well, I understand that but what about the user making changes to it? How would they do that. Would they enter a number? Would they click a button that says move up/down. Ideas?

henry0

12:17 pm on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First come with as many scenario as you may think of

change the query to:

Select * from table order by $order....

$order could be any of the scenario choice passed by POST or GET (for AJAX)

then you may either create an array of the multiple scenario
or load a new table with all the variations

read either the array or the table to offer a drop down box of choices

even better make it an AJAX call so as soon as selected the user will get it.