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
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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.