calculation for accomodation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

calculation for accomodation

Post by ddragas »

My problem is calculation for accomodation.

I've got x periods of year

01/01 - 28/05
29/05 - 02/07
03/07 - 03/09
04/09 - 01/10
02/10 - 31/12

Each period of year has his price for accomodation

for example:

01/01 - 28/05 35€
29/05 - 02/07 45€
03/07 - 03/09 55€
04/09 - 01/10 45€
02/10 - 31/12 35€

Here comes problem

If user wants to spend his vacation on period from 28.06 until 07.07 here come two prices.

Calculation should be: 2 days at price 45€ and 7 day on price 55€

Total of this should be 445€.

periods are in database in timestamp format

if somebody can point me in right direction

regards ddragas
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

Off the top of my head, if someone's period of vacation is stored in db as timestamp, I would sugest using
http://www.php.net/date
then you can get the month / day of start / end and do a function that takes $month and $day and returns the price. That function can have a buncha if/elseifs or a switch statement.
This is a bit of a hack for a solution but it would work, I'm pretty sure theres more efficient solutions to this tho.
Post Reply