# Pricing Issue

Hi all, I’m building a website which is based around hiring items. Every product will be hirable between 2 - 28 days. Obviously the longer you hire an item the higher the price.

Just wondering what the best way to do this would be? Seeing if any of you guys have some alternative solutions. My idea I had was to…

1: Each product row will have a base price (starting price).

2: Each product row will also have an increment price, how much the price should go up by on each day.

3: Run through a loop and somehow times the counter by the incremented value…

Problem is, on some items, I need to increment the price UP TO 15 days, and then to increment it more than the days below 15…!

Appreciated this is a bit of a complicated one

If a product has a daily rate for up to say 15 days, then a cheaper daily rate beyond that and the user hires it for 20 days, do they get all 20 days at the low rate; or the first 15 at the high rate, and the next 5 days at the lower rate?

Hey dude, no it would be a base price of say £10 for two days, £15 for three, £20 for four, £25 for five…and so on incrementing by £5 until the 15th day then the price will increment by £10…

Doesn’t make a lot of sense from a business POV. It’d cost more per day to hire for 16 days than for 15. So someone would just hire for 8 days twice and pay less than hiring for 16 days once.

If that’s right I’d store the minimum term and base rate (2 days, £10) in the product table and create a second table linking the incremental rates to each product

``````
product_id
days
daily_increment

``````

days would be the threshold at which the rate changes, so the data might look like:

``````
3, 5
15, 10

//from 3 days onwards add £5 per day
//from 15 days onwards add £10 per day

``````

Then, once you know the hire term (example 18 days)

``````
SELECT days, daily_increment FROM product_rates WHERE product_id = 320 AND days <= 18
``````

You should then be able to loop over that result set and tally and multiple the rates by the number of days in each price bracket.

Hi there, thanks for your message. I’ve been toying around with a bit of test code but can’t get it to work how I want, please see below:

``````<?php

\$info = array('base'=>10, 'increment'=>5, 'super'=>10);

for(\$i = 1; \$i < 29; \$i++):
echo \$i.' Price &pound;'.number_format(\$info['base']+\$info['increment']).'<br/>';
endfor;
?>
``````

I want it to be like below:

1 Day (£10)
2 Day (£15)
3 Day (£20)
4 Day (£25)
5 Day (£30)
6 Day (£35)
7 Day (£40)
8 Day (£45)
9 Day (£50)
10 Day (£55)
11 Day (£60)
12 Day (£65)
13 Day (£70)
14 Day (£75)
15 Day (£85) – NOW INCREMENTS BY £10
16 Day (£95)
17 Day (£105)
18 Day (£115)
19 Day (£125)
20 Day (£135)
21 Day (£145)
22 Day (£155)
23 Day (£165)
24 Day (£175)
25 Day (£185)
26 Day (£195)
27 Day (£205)
28 Day (£215)

Any help is appreciated as always

``````
<?php

\$base = 10;
\$increment = 5;
\$super = 10;
\$super_at = 15; //days

for(\$i=1; \$i < 29; \$i++) {

//1st day = base price
if( \$i == 1) {
\$price = \$base;
}

//More days, standard rate
else if(\$i < \$super_at) {
\$price = \$base + \$increment * (\$i-1);
}

//More days, higher rate
else {
\$price = \$base + \$increment * \$super_at; //standard rate * standard days
\$price += (\$i-\$super_at)*\$super; //super rate for extra days
}

\$label = (\$i > 1) ? 'Days' : 'Day';

echo "\$i \$label (&pound;\$price)<br>";
}

``````

Hey dude, that’s exactly what I was looking for, massive help. Thank you so much.

The other thing is when a user clicks ‘Add to Basket’, how would I securely add the chosen option from a dropdown menu populated with the above data. Trying to work this out without being hijacked, don’t think I should head down the using the POST value price as an option?

Well you’re just asking them which product they want, and for how many days, and the cart will decide how much it costs using the same function. You’re not asking the user how much they want to pay.