Advice on how to approach this? (calculate availability?)
Posted: Thu Apr 30, 2009 12:58 pm
Hello all,
I have a client who has a membership option. They pre-print cards numbered 1-1600 and give them a card when they join. Members like to keep the same # because they use it when they call in to make a reservation.
Now they don't want to buy 10,000 cards, so they recycle the numbers. If you don't register for the next year, your # goes up for grabs.
I need to know how to figure out the available numbers in PHP/SQL?
I have a row called "member_num" where I have entered some random numbers. 1, 666, 1215, 45, etc. How do I gather all of those up and loop through them until an available number is found?
I imagine it would be something like this:
Select all of the numbers and put them into an array
Starting with 0, loop through SQL queries ("Select * Where member_num=$num AND status=1) and if there is a result, increment +1 until we don't get a result.
Is this the best way to approach this? Is there a more efficient way of discovering "empty" numbers?
Also if this is how I should do it, how do I move the array forward as well as the $num variable?
Let's say we have these numbers already taken: 1, 2, 5
If I do a query on "select where id=1" it will return a result.
How do I move on to the next array and say "select where id=2" until I get an empty result?
Normally I would do the (while X > i){Pull data and increment} kind of approach, but is that the best thing for this particular instance?
Thanks for the help. I'm sorry this isn't a more code-based question but I'm just trying to figure out HOW to do it before I try.
I have a client who has a membership option. They pre-print cards numbered 1-1600 and give them a card when they join. Members like to keep the same # because they use it when they call in to make a reservation.
Now they don't want to buy 10,000 cards, so they recycle the numbers. If you don't register for the next year, your # goes up for grabs.
I need to know how to figure out the available numbers in PHP/SQL?
I have a row called "member_num" where I have entered some random numbers. 1, 666, 1215, 45, etc. How do I gather all of those up and loop through them until an available number is found?
I imagine it would be something like this:
Select all of the numbers and put them into an array
Starting with 0, loop through SQL queries ("Select * Where member_num=$num AND status=1) and if there is a result, increment +1 until we don't get a result.
Is this the best way to approach this? Is there a more efficient way of discovering "empty" numbers?
Also if this is how I should do it, how do I move the array forward as well as the $num variable?
Let's say we have these numbers already taken: 1, 2, 5
If I do a query on "select where id=1" it will return a result.
How do I move on to the next array and say "select where id=2" until I get an empty result?
Normally I would do the (while X > i){Pull data and increment} kind of approach, but is that the best thing for this particular instance?
Thanks for the help. I'm sorry this isn't a more code-based question but I'm just trying to figure out HOW to do it before I try.