Hi guys, I´m attempting to write a simple "get quote" script, but need some advice about best practice. I want to structure it as follows, lets say a customer wants 1,2,3,4 or 5 apples - I want the quote to be $1. If the customer wants 6,7,8,9 or 10 apples - I want the quote to be $2 (this is a very simplified version, and I have no idea of the real price of apples, especially in dollars). Basically if the input value is within a certain predetermined range of values the output should correspond to that specific range. Do i do this using just a php file with the ranges as variables, or do i use mysql to connect with a database which contains the ranges as variables. Also any help with how to do either would be great, I am a little rusty with coding at the minute!
Many thanks!

Recommended Answers

All 2 Replies

How'd i do it?
lets see.. 1 - 5 is $1 (or rather 1unit price), 6 - 10 is $2... so i have a 'range' of 5
I'll need 2 variables

$range = 5;
$unit_price = 1; /*$1 or may be $10*/

then i'll accept the product count from user (sanitized and typecasted to int)
So the price wud be calculated as

$total_price = ceil($no_of_products/$range) * $unit_price;

If the project isn't much significant and there's no chances of it growing big in future, being a lazy person i'd hardcode the values of $range and $unit_price in my config.php.
But in a world dominated by CMS'es you better save these into your database and may be even provide a little form in some corner of the admin area to update them !

Thanks ckchaudhary, that worked a treat!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.