Is this code right, I am trying to update a field in the database after doing some calculations, I get the calculations to come out right but not updating the database at the end.
mysql_connect("","","");
mysql_select_db("");
$query = "SELECT MIN(CLOSEDATE), MAX(CLOSEDATE), VIN, CUSTOMERNAME, MIN(MILEAGE), MAX(MILEAGE) FROM LUTHERSELLANDRECOMMEND GROUP BY VIN LIMIT 10";
$result = mysql_query($query);
echo "<table border=2 bordercolor=#5E3964>\n";
echo " <tr>
<td><font color=#800303>Min Closedate</font></td>
<td><font color=#800303>Max Closedate</font></td>
<td><font color=#800303>VIN</font></td>
<td><font color=#800303>Customer Name</font></td>
<td><font color=#800303>Date Difference</font></td>
<td><font color=#800303>Min Mileage</font></td>
<td><font color=#800303>Max Mileage</font></td>
<td><font color=#800303>Mileage Difference</font></td>
<td><font color=#800303>Miles Per Day</font></td>
</tr>\n";
while ($row = mysql_fetch_array($result)) {
$date1 = $row["MIN(CLOSEDATE)"];
$date2 = $row["MAX(CLOSEDATE)"];
$time1 = strtotime($date1);
$time2 = strtotime($date2);
$time = @round($time2-$time1,0);
$datedifference = $time/60/60/24;
$mileage1 = $row["MIN(MILEAGE)"];
$mileage2 = $row["MAX(MILEAGE)"];
$mileagedifference = @round($mileage2-$mileage1,0);
$milesperday = @round($mileagedifference/$datedifference,0);
$vin = $row["VIN"];
print"
<tr>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>{$row["MIN(CLOSEDATE)"]}</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>{$row["MAX(CLOSEDATE)"]}</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>$vin</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>{$row["CUSTOMERNAME"]}</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>$datedifference</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>{$row["MIN(MILEAGE)"]}</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>{$row["MAX(MILEAGE)"]}</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>$mileagedifference</font></td>
<td><font color='#000066' size='2' face='Verdana, Arial, Helvetica, sans-serif'>$milesperday</font></td>
</tr>";
for($i = 0; $i < count($vin); $i++){
$query1 = "UPDATE LUTHERSELLANDRECOMMEND SET miles_per_day ='$milesperday[$i]' WHERE VIN='$vin[$i]'";
print $query1."<br />";
$result1 = mysql_query($query1) or die(mysql_error());
}
}
echo "</table>";