
Originally Posted by
9greej10
I am a little confused as to the best way to tackle this, because lets say I have the following list and I want to move ‘find us’ to 2nd from the top – how would I perform this in terms of manipulating the recordset and using logic?
PageID PageName pageSort
1 home 1
2 aboutus 2
3 our services 3
4 products 4
5 find us 5
OK, this is what I would do...
Code:
'## Pass the Current PageID & the direction via a querystring... your link for moving 'find us' up one position would look something like this..
<a href="?move=up&pageID=5">Move Up</a>
Code:
<%
If Request.QueryString("move") <> "" AND Request.QueryString("pageID") <> "" Then
pageID = Request.QueryString("pageID")
SQL = "SELECT sortNumber FROM Pages ORDER BY sortNumber DESC"
Set RS = DB.Execute(SQL)
If RS.EOF Then
Else
fSortNumber = RS("sortNumber") '## The original / starting sort number
If Request.QueryString("move") = "up" Then
nSortNumber = fSortNumber - 1 '## The new / next sort number
Else
nSortNumber = fSortNumber + 1 '## The new / next sort number
End If
'## Now check 'Pages' table for any pages that already have that position (nSortNumber).
SQL = "SELECT pageID, sortNumber FROM Pages WHERE sortNumber=" & nNumber"
Set RS = DB.Execute(SQL)
If RS.EOF Then
'## There is no other page sharing this position, so no need to update any.
Else
uPageID = RS("pageID") '## The ID of the page we are swapping the sort number with
SQL = "UPDATE Pages SET(sortNumber=" & fPageNumber & ") WHERE pageID=" & uPageID
DB.Execute(SQL)
End If
'## Now that we've "swapped" the sortnumber for the existing page we can update our page with the new sortnumber
SQL = "UPDATE Pages SET (sortNumber=" & nPageNumber & ") WHERE pageID = pageID
DB.Execute(SQL)
%>
I apologise if this is a bit hard to follow... Basically, this is what happens in laymen's terms...
- Get the last sortnumber (the largest).
- Calculate the new sortnumber for the page('find us') we will be moving (up/down).
- Search the database for any pages which already have this sortnumber
- If found, update this page (in this case 'products') with the sortnumber of the page we want to move ('find us').
- Now update the page we are moving with the new sort number.
Let me know if you want any more explanation... I may well have confused myself somewhere along the line!
Bookmarks