Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP programming

Posted on 2012-08-28
7
Medium Priority
?
269 Views
Last Modified: 2012-12-13
Hi experts.

I have this particular request:
Customer registers and pay via payment gateway.

I need every 5th registrant/payment to be free.

So, 1st, 2nd, 3rd, 4th, pays, 5th free of charge. And then 6th, 7th, 8th, 9th, pays, 10th is free of charge.

I just couldn't figure out the programming logic. Any sample code that I could rely on for this?
0
Comment
Question by:rolandmy
6 Comments
 
LVL 25

Assisted Solution

by:lwadwell
lwadwell earned 600 total points
ID: 38343884
I am assuming these registrant's are separate people/separate sessions.  If so - each execution of the PHP code will be different from the others and you will need to keep a counter of the number of registrants elsewhere that can be accessed by the PHP code ... a database table, a file of some form.  Depending on how 'busy' these registrations will be - you may need to consider concurrency and locking.
But basically you would
a) determine the number of the current registrant ("select count(*) from ...", read from the file...etc)
b) determine if 5th by using the % (modulus) operator
<?php $rem = $count % 5; if ( $rem = 0 ) echo "you are the 5th"; ?>
0
 
LVL 18

Assisted Solution

by:Garry Glendown
Garry Glendown earned 400 total points
ID: 38344605
I'd say checking for concurrency/race conditions isn't a "may need to" but necessary even with low volume sites ... doing a simple count will not be safe enough ... also, you'll need to decide upon the logic of assigning the free registrations - at what point is the free registration (or the sale in general) counted and price finalized? What happens if a registrant cancels at some point of the process, how are subsequent registrants handled that started afterwards, but went through with the registration?
I don't know your experience level in progamming - or rather designing - but maybe taking a piece of paper (or Visio etc.) and plotting out some sort of flow chart of the registration and decision process would help you (and maybe give people on here an idea what to suggest as for the program logic and implementation)
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 600 total points
ID: 38345394
Insert each registration into a data base table.  You do not need to lock the table or be concerned about race; just get the AUTO_INCREMENT id back with something like mysql_insert_id()  Then use the remainder (see above) to see if this is one of the 5th registrants.  If the remainder is zero, the price is zero.  All others pay.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:rolandmy
ID: 38686606
Didn't use.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38687912
@rolandmy: Withing less than 24 hours of posting this question, you received exactly the correct answers here.  Yet you ignored the question for months, never responded and then gave your fellow experts the worst possible grade anyone can give at EE.  I think we are entitled to an explanation.  Please read the grading guidelines and then tell us why you did that.  Thanks, ~Ray

http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26
0
 
LVL 2

Author Comment

by:rolandmy
ID: 38690124
Ooops. I didn't read the guidelines. My bad. I apologize. As I didn't use the solution, I thought I'd just rate it as a C. And I didn't put it into knowledge base.

Won't happen again since I already read the guidelines as below.

An A grade should be given if you receive the solution from the Experts; you should consider the A grade the default unless it is deficient.
A B grade should be given if the solutions require you to do a good amount of extra work to resolve your problem.
A C grade is the lowest possible grade you can give. Experts should always be given the opportunity to improve it -- but that does not mean they should rewrite your entire application for you.

It is customary to explain any grade that is not an A.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question