Jump to content

candles in packages of 1,2,3,4,5 and 6


phppup

Recommended Posts

Details:  Working for a company that sells candles in packages of 1,2,3,4,5 and 6. 

Their website is set, and their database is adequate.

 

Situation: I need to be able to breakdown large orders for efficient packaging.  So, if a customer orders twelve candles, I could transpose the order into 2 six-packs.  If the order were for sixteen candles, the order would transpose to 2 six-packs and 1 four-pack.  Always using the largest sized sets possible.

Do NOT want an order for 12 being assembled as 3 fours or 4 threes, as it is inefficient.

 

Can the quantity be INSERTED into the table accordingly, or does it need to be inserted as 16 (for example) and then broken down afterward??

 

I am not sure whether I can do this in PHP or if a JavaScript is better.

 

Obviously, i need to divide the largest orders by six, but not sure how to get that number, and how to incorporate the remainder.

 

Please help.

 

i used to have a stress ball.... ya know, those rubbery things for you to squeeze and throw to AVOID real damage, but I broke it! 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/257215-candles-in-packages-of-12345-and-6/
Share on other sites

You should definitely use PHP to calculate, not Javascript. Using JS will allow malicious users to play with the code and enter obscure order / shipping details.

 

divide and use modulus to find the remainder.... this will give you an idea

$amount = 20;
$remainder = 20 % 6;
$result = ($amount - $remainder) / 6;
$extra = ($remainder < 4)?'1 4pack':'1 6pack';
echo "$result x 6packs <br> $extra";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.