php - Calculate price form excel javascript

901

On a website the customer fills in a height and a width. I round up the number withecho round(657, -2, PHP_ROUND_HALF_UP); for example.

So now i have my width & height in hundreds. Just like my price scheme: *breedte = width, hoogte = height in millimeters. The result is a price. enter image description here

The calculation would have been simple if there was a formula. Like Width * height = X. X * Y = the price. But we don't know Y. Client says Y is irregular and cannot be found. We think otherwise. For the math guys, if someone can find a formula you have my eternal thanks.

Now the real question. Let's say I would turn this into a massive function with php or fill it in a database to calculate the price. Would be a painful. But what is the best way to do it? Php function? Javascript function? Fill up a database and retrieve the price from there?

980

Answer

Solution:

If you can find a pattern in the data and are able to calculate it from the X and Y coordinates, you can make it a function. Preferably in the business logic of your application (that would likely be PHP, not Javascript).

Otherwise you'll be looking at a lookup table. It's best not to hard-code these, and for maintainability you're going to want to put these values either in a file or database separate from your code, so you can adjust them easily in the future.

I'd suggest either using a database or a CSV-like file, which can easily be edited by non-tech people using the right software.

People are also looking for solutions to the problem: php - Yii2 multiple models loop save error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.