Could someone help me with this code? I need to compare the date completed(datecomp) to the date paid(datepaid) to establish the number of days difference(dayslate). Thanks in advance!

<?php
$stat = mysql_connect("localhost","root","");
$stat = mysql_select_db("oodb");
$query = "SELECT name FROM oocust Where ordernum='$ordernum'";
$stat = @mysql_fetch_assoc(mysql_query($query));
echo $stat["name"];
$result= mysql_query("select * from oocust WHERE pd=' '");
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$pd=$row['pd'];
$datecomp=$row['datecomp'];
$datepaid=$row['datepaid'];
$charges=$row['charges'];
$paidamt=$row['paidamt'];
$owed=$row['owed'];
$dayslate=$row['dayslate'];
$tax=$row['tax'];
$amtdue=$row['amtdue'];

// $dayslate = $datecomp - $datepaid;

 function number_of_days($date1, $date2)
 {  
 $date1Array = explode('/', $date1);  
 $date1Epoch = mktime(0, 0, 0, $date1Array[1],  
 $date1Array[0], $date1Array[2]);  
 $date2Array = explode('/', $date2);  
 $date2Epoch = mktime(0, 0, 0, $date2Array[1],  
 $date2Array[0], $date2Array[2]);  
 $dayslate = $date2Epoch - $date1Epoch;  
 return round($dayslate / 60 / 60 / 24);  
 }  
 echo number_of_days("04/7/2009", "12/7/2009");


 if ($paidamt == $amtdue)
{
$pd = 'P';
}
$tax = $charges * .06;
$owed = $charges + $tax + $shipamt - $paidamt;
$sql = "UPDATE oocust SET
pd='$pd', owed='$owed', dayslate='$dayslate', tax='$tax' 
WHERE id='$id'";
mysql_query($sql) ;
$err=mysql_error();
if($err!=""){
  echo "Error in $sql: $err\n";
}
}
echo "Records have been updated";
?>

take your declaration of function number_of_days
outside your while loop
best is top of the script

Do not declare your function inside the loop. That will make your function declared as many as the loop iterate and php don't allow it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.