phppup Posted February 17, 2012 Share Posted February 17, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/257215-candles-in-packages-of-12345-and-6/ Share on other sites More sharing options...
joel24 Posted February 17, 2012 Share Posted February 17, 2012 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"; Quote Link to comment https://forums.phpfreaks.com/topic/257215-candles-in-packages-of-12345-and-6/#findComment-1318508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.