ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 27th, 2003, 01:25 PM
esthera esthera is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 esthera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking sorting categories

I need an order logic. In otherwords I have a db with 2 relavant fields category and categorypriority. I need to be able to let the user change the priority and when priority is changed to one (the highest) all the other priorities are shifed down and the same thing if the priority is changed to say 5 then 5 needs to move.

Does anyone have any suggestions?

Reply With Quote
  #2  
Old August 27th, 2003, 01:41 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
do you have more than 5 categories?
If so, can there only be one priority 1 and one priority 5? If the user makes something priority 1, do all the other priorities stay in order, or does just the old priority 1 need to change?
__________________
- Rogier Doekes

Reply With Quote
  #3  
Old August 27th, 2003, 01:48 PM
esthera esthera is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 esthera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
There can be many categories but I will know the number (from the number of categories in the recordset)

The tricky part is if they change category 6 to be category 1 then category 1 has to move to 2 and 2 to 3 etc....

Reply With Quote
  #4  
Old August 27th, 2003, 07:55 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You just need to loop through your records and perform a query like this (this will raise the priorities)
Code:
for idx = lowestPriority to highestPriority
   UPDATE table SET priority = priority + 1 WHERE priority = " & idx
next

Reply With Quote
  #5  
Old August 28th, 2003, 02:10 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
hey stump, I believe your code will result in all records having the highest priority.

esthera, I think you need to add a field in your table old_priority, which you initialize to the priority.

Then the code will be
Code:
for idx = lowestPriority to highestPriority
   UPDATE table SET priority = priority + 1 WHERE old_priority = " & idx
next
UPDATE table SET old_priority = priority


Let me know if I whiff on this pitch

Reply With Quote
  #6  
Old August 28th, 2003, 02:15 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Yes - I think you're right... I had another look @ the code I had written that uses this single increment method, and noticed that the WHERE is looking for the record ID, rather than the priority. Hopefully esthera gets the general idea tho.

I'm not sure what your second update statement achieves in it's current form tho rdoekes? Are you missing the WHERE statement?

Reply With Quote
  #7  
Old August 28th, 2003, 02:23 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
i was trying to make the old_priority the same as the changed priority.

But i agree with you, that if you use the recordID for the loop your code will work fine. But you need to exclude the record which was set to the lowest priority:
Code:
UPDATE table SET priority = 1 WHERE recordID = xxx

for idx = firstrecord to lastrecord
  If Not idx = xxx Then
   UPDATE table SET priority = priority + 1 WHERE recordID = " & idx
  End If
next

Reply With Quote
  #8  
Old August 28th, 2003, 03:05 AM
esthera esthera is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 esthera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your help. I am going to try this. But will this also work if they want to say change id 10 to priority 5 from 8 for example.

I also want to let them change priorities. The priority should only move up if it is larger than the set priority.

Thanks,
esther

Reply With Quote
  #9  
Old August 28th, 2003, 03:26 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
There's nothing really technical we can help you with. It's now just down to your logic. The best way to tackle a problem like this is to sit down with piece of paper and step though the problem, thinking about each step, and writing out some psuedo-code.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > sorting categories


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT