|
-
Apr 30th, 2009, 10:45 AM
#1
Thread Starter
Fanatic Member
php confirmation numbers timed
Hello, thanks for reading this.
I would like to have a timed promotion on a website for members.
I want to send a promotion to them via email that will have a random confirmation number on it. I would like to keep it unique to each person, so each member will have a separate confirmation number.
When they enter the site and type the confirmation number, they get a discount (for example).
I currently host online with hostmonster.com. I use PHP/MySql.
How can I get started figuring out how to do something like this? I was even hoping to have an expiration date assigned to each promotion code.
Thanks!!!
-
Apr 30th, 2009, 12:48 PM
#2
Re: php confirmation numbers timed
I think it would be much easier to use just one confirmation number per promotion, just so that you don't need to get into making a ton of different numbers and then also keeping track of them all in your database. using either one universal code or a unique code for each user is possible and for the most part, they're pretty similar. but, I'll go through using one universal code since it's just a tad easier.
you would first most likely need to make a new table (promotions) that stored all of your promotions. this table might need to store the promotion id, name, confirmation code, start date, and end date, and of course, how much of a discount. but be consistent: if you want the ability to have both percentage based discounts AND flat value discounts (eg. some promotions could be 10% off, whereas some could be $5 off), then make two fields. one field would be an enum with different discount types (percentage, flat rate), and the second field would be the value of that discount. you can do the logic to sort it all out later.
then, you could make another table (promotions_applied?) that stores which users have applied said codes already. this table would need to only store the promotion id, user id, and maybe the date that they applied it (if you care).
so, when the user visits your site and applies a code, you can first check the promotions_applied table to see if they have already applied that or not. obviously, you don't want to waste time adding to your database if they've already added that promotion. if they haven't, you insert a new record with their user ID and the promotion ID of the code that they just put in. then, at least for this part, you're done.
when the user is checking out, you can then pull up the promotions_applied table and see what promotions are on this user's account. if there are more than one, you could only take 1 (1 per order, or whatever), or take them all. you could then loop through the promotions table (making sure that it isn't over the expiration date) with these applied IDs and add everything up, and then apply it to the total of the user's order.
if you only want the user to be able to use each promotion once, you could also add a "used" field to the promotions_applied table and when checking if any promotions are applied to the user's account during check out, you could simply add a clause that checks if the user has used it yet or not.
hope you're okay with just theory, and hopefully that all made sense. ask some questions if it didn't!
-
Apr 30th, 2009, 02:41 PM
#3
Thread Starter
Fanatic Member
Re: php confirmation numbers timed
kows, you're aweseme.
I understand what you are saying completely. I agree now, after reading your post, that one code makes sense. I didn't think of the promotions_applied table.
What I should do is what you are saying. Make the promotions_applied table and check that table before the promo is given to the user. If there is no record in there for that user_id, then add it...
But, I probably should have a step just before I add it to make sure the promo isn't expired. So if there is no record in the promotions_applied table for that user_id and promo_id, then check the promo_expiration to make sure it is less than the current date.
If it is... THEN add the record to the promotions_applied. Otherwise, right away I can inform the user that the promo has expired or if they have already used that promo code before.
When the user checks out, then I should also recheck the promo_expiration for the promo_id to make sure it is still not expired... then apply the discount.
How does that sound? Comments, criticism or suggestions?! :-)
I'm a newbie to this stuff, but I like to learn it.
Thanks a lot. Great advice.
-
Apr 30th, 2009, 04:30 PM
#4
Re: php confirmation numbers timed
yes, that's exactly right. let me know if you need any help implementing it.
-
Apr 30th, 2009, 08:17 PM
#5
Thread Starter
Fanatic Member
Re: php confirmation numbers timed
I will let you know, thank you very much for your help.
*I tried to add to your reputation, as I always do when people help me, but I have to "spread some reputation around." I guess I had recently done that. So I can't right now. :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|