need a bit of logic help here

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

need a bit of logic help here

Post by Burrito »

I have some courses that are being taught in a table. This table has 3 fields:

courseid
userid
courseorder

a user can be enrolled in five courses at a time so the courseorder might be like this:

courseid - courseorder
1 - 3
2 - 4
3 - 2
4 - 1
5 - 5

my question is, if I delete two of those courses, say courseid's 2 and 4, how can I reset the course order?

courseid - courseorder
1 - 3
3 - 2
5 - 5

now needs to be:

courseid - courseorder
1 - 2
3 - 1
5 - 3

my wee little pee brain can't figure this one out
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

select them sorted by course order ascending. update them starting from 1, incrementing with each row.
Post Reply