0

Im making a rentals script but when they rent an object for more then 5 days something goes wrong.

this is how it should work:

when someone rents an object for 1 till 5 days they should pay that amount of days, but when they rent for 6 or 7 days they just have to pay for 5 days, this works for every 7 days they rent a object.

so 10 days will be 8 days paying

this is the script i already have:

function bedrag($fietsnummers, $aantaldagen)
{

$fiets = explode(',', $fietsnummers);
foreach($fiets as $fiets1)
    {
        $sql2 = "SELECT * FROM `fietsen` WHERE `fietsnummer` LIKE '".$fiets1."' LIMIT 0, 30 ";
        $nummer = mysql_query($sql2)or die(mysql_error());

    while ($fietsinfo = mysql_fetch_array($nummer)) 
    {
        $nummer1 = $fietsinfo['huurprijs'];
        $bonus = intval($aantaldagen / 7);
        $aantaldagen -= 2 * $bonus;
        if($aantaldagen == "0")
        {
        $aantaldagen = "1";
        }
        $bedrag = $nummer1 * $aantaldagen;
        $amount += intval($bedrag);

    }
    }

    return $amount;


}
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Wessel s
  • 1
  • 4
  • And what does the script you have do? Where doesn't it work? – andrewsi Jul 03 '12 at 17:37
  • it calculates the amount of days the person should pay, searches for the price for the object per day and then calculates the price – Wessel s Jul 03 '12 at 17:39
  • Welcome to StackOverflow. PHP's `mysql_*` functions are [deprecated](http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated). The [suggested alternatives](http://www.php.net/manual/en/mysqlinfo.api.choosing.php) for new code are [easier to use safely](http://stackoverflow.com/a/60496/132382). – pilcrow Jul 03 '12 at 17:40

1 Answers1

0

Here the function returning bill days

function billablePeriod($days){

$full_weeks = intval($days/7);
$current = $days%7;

$bonus = $full_weeks*2;
$bonus += ($current-5)>0? ($current-5) : 0;


return $days -$bonus;
}

ADD AND FIXED on comment

in your code:

$amount =0;
while ($fietsinfo = mysql_fetch_array($nummer)) 
{
    $amount += $fietsinfo['huurprijs'] * billablePeriod($aantaldagen);
}
Ivan Buttinoni
  • 4,110
  • 1
  • 24
  • 44
  • the $fietsinfo['huurprijs'] is the price for the object per day, the $aantaldagen is the amount of days the person rented the object. – Wessel s Jul 03 '12 at 18:03