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

## 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.

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!

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

##### Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

## Join the conversation

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.