Sorting like Amazon DVD system

M

Mojo

Hi All

Just wanted to know how hard it is to create a little routine to copy what
Amazon's My DVD list used to do.

Basically you had a list of say 30 DVDs and you could define the order of
preference either by using Move Up or Move down buttons (this bit doesn't
seem to hard) or by changing the preference number of a DVD, which then
sorted all the ones below it, eg:

1 Star Wars
2 Shrek
3 Superman
4 LotR
5 Batman
6 Next
7 Open Season
8 Bambi
etc etc

In their sys you could go into a text box and change say Open Season's
number from 7 to 2. This would make Open Season my 2nd pref and all the
others would drop down, eg:

1 Star Wars
2 Open Season
3 Shrek
4 Superman
5 LotR
6 Batman
7 Next
8 Bambi
etc etc

If I'd put Open Season at 340 then it would automatically put it at the
bottom, but it wouldn't be 340 it would be the last number, eg 21

How the hell do you do this with ASP and DB that's holding this data? I
just don't get how you get to move them down from a 'floating' point!

Any advice you can give would be appreciated.
 
B

Bob Barrows

Mojo said:
Hi All

Just wanted to know how hard it is to create a little routine to copy
what Amazon's My DVD list used to do.

Basically you had a list of say 30 DVDs and you could define the
order of preference either by using Move Up or Move down buttons
(this bit doesn't seem to hard) or by changing the preference number
of a DVD, which then sorted all the ones below it, eg:


In their sys you could go into a text box and change say Open Season's
number from 7 to 2. This would make Open Season my 2nd pref and all
the others would drop down, eg:


If I'd put Open Season at 340 then it would automatically put it at
the bottom, but it wouldn't be 340 it would be the last number, eg 21

How the hell do you do this with ASP and DB that's holding this data?
I just don't get how you get to move them down from a 'floating'
point!

I'm not sure why you would think this is a problem. Just add a SortBy
column and use that in the ORDER BY clause in the query used to retrieve
the records. You would likely need to write code to add 1 to the SortBy
field of all the records where SortBy >= to the new SortBy value of the
record.
 
D

Dave Anderson

Mojo said:
Just wanted to know how hard it is to create a little routine to copy
what Amazon's My DVD list used to do...

We have done such a thing for reordering intranet headlines. Our ASP is in
JScript, but the idea would be the same in VBScript.

For starters, our "Queue" has two inputs for each item -- a hidden field
with the record ID and a text input displaying the rank. For example:

<input type="hidden" name="HeadlineID.1" value="12345" />
<input type="text" name="Order.1" value="1" />
<input type="hidden" name="HeadlineID.2" value="56789" />
<input type="text" name="Order.2" value="2" />

The ASP script is very simple:

for (var a=[],i=0; i<=Request.Form.Count; i++)
if (Request.Form("Order."+i).Count &&
Request.Form("HeadlineID."+i).Count)
a.push(
{
ID: Request.Form("HeadlineID."+i).Item/1,
New: Request.Form("Order."+i).Item/1,
Old: i
}
)
a = a.sort(function(a,b){ return 1000*(a.New-b.New) - (a.Old-b.Old) })

This is followed by an update in the database to each element in the array.

It works because we give much more weight to the changed values than to the
existing ones. If our lists were enormous, we would need a multiplier larger
than 1000.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top