ThomasJSmart
Programmer
- Sep 16, 2002
- 634
Hi,
Iv made this preference system but its quite a lot of code so im wondering if theres an easier way to do it.
Var1 can be 1 or 0
Var2 can be 1 or 0
Var3 can be 1,2,3 or 4
var4 is the id / entry order
The preference system needs to asign entries to category A (cata) or category b (catb).
to keep it easy lets say cata can have 5 entries, all others need to go into catb.
the optimal entry for cata is
var1: 1
var2: 1
var3: 4
var4: lowest
so say we have 5 entries with the above vars then a 6th entry is added with the same vars. this 6th entry would be put into catb becuase var4 would be higher than the rest.
it gets more complicated tho because say we have 5 entries, 4 entries have the same vars as above, and the entry with the lowest var4 has the following vars:
var1: 0, var2: 1, var3: 2.
now lets say another entry is added with the optimal vars again, the entry with the lower var1/var3 would have to be moved to catb and the new entry would be put in cata.
i hope this is clear >.<
the full system is a bit more complicated but if i can get some help with this bit i can sort the rest out myself.
The way i have done it now is to just check all current entries against the new one, but this requires a string of code per var option combination....
entries are put into a mysql database by the way so to update a current entry i will need to retrieve the ID for the entry that needs to be changed.
im sure theres a way to get the "lowest possible entry currently in database" and just compare that one to the new one... but i cant think how to do it : /
thank you.
I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
Iv made this preference system but its quite a lot of code so im wondering if theres an easier way to do it.
Var1 can be 1 or 0
Var2 can be 1 or 0
Var3 can be 1,2,3 or 4
var4 is the id / entry order
The preference system needs to asign entries to category A (cata) or category b (catb).
to keep it easy lets say cata can have 5 entries, all others need to go into catb.
the optimal entry for cata is
var1: 1
var2: 1
var3: 4
var4: lowest
so say we have 5 entries with the above vars then a 6th entry is added with the same vars. this 6th entry would be put into catb becuase var4 would be higher than the rest.
it gets more complicated tho because say we have 5 entries, 4 entries have the same vars as above, and the entry with the lowest var4 has the following vars:
var1: 0, var2: 1, var3: 2.
now lets say another entry is added with the optimal vars again, the entry with the lower var1/var3 would have to be moved to catb and the new entry would be put in cata.
i hope this is clear >.<
the full system is a bit more complicated but if i can get some help with this bit i can sort the rest out myself.
The way i have done it now is to just check all current entries against the new one, but this requires a string of code per var option combination....
entries are put into a mysql database by the way so to update a current entry i will need to retrieve the ID for the entry that needs to be changed.
im sure theres a way to get the "lowest possible entry currently in database" and just compare that one to the new one... but i cant think how to do it : /
thank you.
I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!