Hello!
I need your help for the following problem:
These are my tables
bonusCodes (called bc from now on)
id
code
users
maxinvoices
maxusers
activefrom
activeuntil
forfatter
dato
usedBonusCodes (called ubc from now on)
id
codeid (henviser til bonusCodes.id)
fakturaid
forfatter
dato
question
what I want is the query to return the bc.code IF:
c.users = $user OR c.users = '0'
bc.maxinvoices > the number of counts in ubc WHERE "fakturaid" = $fakturaid AND codeid = $code. Furthermore there must be no more than ONE different codeid WHERE fakturaid=$fakturaid AND userid=$user
bc.maxusers > the number of users that have used the code ONCE! det, jeg gerne vil, er, at jeg i bonusCodes vil kunne tilføje forskellige parametre, der kan gøre en bonuscode valid.
I want to be able to combine bc.activeuntil and bc.activefrom with "users", "maxusers" and "maxinvoices" - so I can either set them to 0000-00-00 00:00:00 and then it will return bc.code until maxinvoices = the count of used codes and the same for users - if users is = 0 it should return from the same conditions as for maxinvoices