repost..sorry...but...I want to find the way out..

Results 1 to 3 of 3

Thread: repost..sorry...but...I want to find the way out..

  1. #1
    Join Date
    Dec 1969

    Default repost..sorry...but...I want to find the way out..

    Hi all,<BR><BR>In continuation to this post yesterday.... on which i had no positive results..<BR><BR><BR><BR>I want to have prevrecord (value), currentrecord value and the nextrecord value<BR><BR>I cannot have recordcount-1..what if I delete one of the records..then i will go wrong..<BR><BR><BR>I need to move the position of the current record to the precvious record or to the next record....for this i need to have the prevrec value and nextrec value so that i can use a update statement and just edit the current to the prev, if the data has to be moved up..and viceversa...<BR><BR><BR>that if the current recordval is 7 and my prev recordval is 5 and the next recordval is 11.<BR><BR>if I want to move one level up then i use update query and swap 7 to 5. <BR><BR><BR>or what is the best way to move current record one level up(above) or one level down(below)...<BR><BR><BR>Thanks for time and input.<BR><BR>Cheerss<BR><BR>Jay

  2. #2
    Join Date
    Dec 1969

    Default RE: repost..sorry...but...I want to find the way o

    For your "Previous" and "Next" links<BR><BR>Store the "Current Records ID", Say ID is 55...<BR><BR>Then in code, 1st determine which was selected (previous or next)<BR><BR>And run a different query accordingly<BR><BR>IF Previous<BR>SQL="Select Top 1 ............ where ID &#060; 55 Order by ID Desc<BR><BR>IF Next<BR>SQL="Select Top 1 ............ where ID &#062; 55 order by ID Asc<BR><BR>That way it doesnt matter if there is a gap of 10 or 1000 in the ID&#039;s, it will always find the next 1 in line...<BR><BR>hope it helps.

  3. #3
    Join Date
    Dec 1969

    Default WOW

    THAT is not how I took your post yesterday at all. I thought you wanted to page through a large recordset. If I&#039;m understanding you right I think you want to be able to allow the user to sort records order. So you want a list of items that looks something like this:<BR><BR>Table1<BR>1 Data1 <BR>2 Data2<BR>4 Data4<BR><BR>and you want to be able to move the values up and down? I did this in a project. But I had some business rules that kept me from having gaps in the numbers I used. Here&#039;s a very long winded example:<BR><BR>Table1<BR>seq Text ordernumber <BR>--- ---- --------<BR>1 Data1 1<BR>2 Data2 2<BR>4 Data4 3<BR><BR>Notice though the sequence (unique key) has a gap the ordernumber does not. There may be another way but this is how I did it. When you delete a value you need to fix the order, when you add a value you need to make sure to keep the order, no gaps are allowed otherwise it won&#039;t work.<BR><BR>For the code to move an item you need to start by having a link for each row so you know which seq column was clicked, and the direction. So for example sequence 4 to move an item up:<BR><BR>&#060;a href="pagename.asp?move=up&seq=4&ordernumber=3"&#0 62;&#060;%=seq%&#062;&#060;/a&#062;<BR><BR>On your resulting page get back the seq and direction var:<BR>move = Request.QueryString("move")<BR>seq = Request.QueryString("seq")<BR>ordernumber = Request.QueryString("ordernumber")<BR><BR>Now build your sql to move the existing record up (decrease the ordernumber by 1):<BR>SQL = "Update Table1 set ordernumber=ordernumber-1 where seq=" & CStr(seq)<BR><BR>Execute it. Now in the database you have this:<BR><BR>Table1<BR>seq Text ordernumber <BR>--- ---- --------<BR>1 Data1 1<BR>2 Data2 2<BR>4 Data4 2<BR><BR>Now move the record above it down, but make sure to not move the one you just moved, so you need the seq<BR>of the record you moved as well as the order number of the previous above record. You can get this by subtracting<BR>from the ordernumber of the record clicked so we do:<BR>SQL = "Update Table1 set ordernumber=ordernumber+1 where ordernumber=" & CStr(ordernumber-1) & " AND " & _<BR>"seq &#060;&#062; " & seq<BR><BR>When we do this we get the following:<BR><BR>Table1<BR>seq Text ordernumber <BR>--- ---- --------<BR>1 Data1 1<BR>2 Data2 3<BR>4 Data4 2<BR><BR>When we re-order by ordernumber we have moved a record<BR><BR>Table1<BR>seq Text ordernumber <BR>--- ---- --------<BR>1 Data1 1<BR>4 Data4 2<BR>2 Data2 3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts