while loop not repeating

hi, using “while” to perform multiple INSERT INTO in MySQL using date increment. It does the first insert and echo’s the next value but does not repeat. only one record gets inserted. code below, thanks in advance.

$startdate = $_POST[“startdate”];
$enddate = $_POST[“enddate”];
$nextdate = $startdate ;

while($nextdate <= $enddate){

$query = “INSERT INTO history rent roll (RRDate, RRMktRent, RRLTL, RRAptRent, RRPetRent, RRUtilFee, RRCharge1, RRCharge2)
SELECT
‘$nextdate’,
SUM(units.MktRent)/DAYOFMONTH(LAST_DAY(’$nextdate’)),
SUM(units.MktRent - leases.AptRent)/DAYOFMONTH(LAST_DAY(’$nextdate’)),
SUM(leases.AptRent)/DAYOFMONTH(LAST_DAY(’$nextdate’)),
SUM(leases.PetRent)/DAYOFMONTH(LAST_DAY(’$nextdate’)),
SUM(leases.UtilFee)/DAYOFMONTH(LAST_DAY(’$nextdate’)),
SUM(leases.Charge1)/DAYOFMONTH(LAST_DAY(’$nextdate’)),
SUM(leases.Charge2)/DAYOFMONTH(LAST_DAY(’$nextdate’))
FROM units
LEFT JOIN leases
ON (units.UnitID = leases.UnitID)
AND (((leases.LeaseStart <= ‘$nextdate’)
AND (leases.LeaseEnd >= ‘$nextdate’)
AND (ISNULL(leases.MoveOut)
OR (leases.MoveOut >= ‘$nextdate’)))
OR ((leases.LeaseStart <= ‘$nextdate’)
AND (leases.LeaseEnd <= ‘$nextdate’)
AND (ISNULL(leases.MoveOut)
OR (leases.MoveOut > ‘$nextdate’))
AND (ISNULL(leases.LeaseStatus)
OR (leases.LeaseStatus <> ‘Renewed’))))”;

$result = mysql_query($query);

$nextdate = strtotime("+1 day", strtotime($nextdate));

echo "date = “,$nextdate,” ",date(“Y-m-d”,$nextdate);

}

Sponsor our Newsletter | Privacy Policy | Terms of Service