Forum Moderators: coopster
<?php
$stat = mysql_connect("localhost","root","");
$stat = mysql_select_db("oodb");
$query = "SELECT charges, dayslate FROM oocust Where WHERE payrec = 'R' AND pd = ' '";
$stat = @mysql_fetch_assoc(mysql_query($query));
echo $stat["charges"];
$result= mysql_query("select * from oocust");
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$dayslate=$row['dayslate'];
$duedate=$row['duedate'];
$tax=$row['tax'];
// sysdate = date("m/d/y");
// if(strtotime($sysdate) > (strtotime($row["duedate"]) +2600000)
}
$sql = "UPDATE oocust SET
tax = charges * .06,
dayslate = '$dayslate'
WHERE id='$id'";
mysql_query($sql) ;
$err=mysql_error();
if($err!=""){
echo "Error in $sql: $err\n";
}
}
echo "Records have been updated";
?>
"I need to calculate the # of days late (dayslate)(# of days from the duedate to the current date. Below is my code."was intended to solicit help. I'm sure the code doesn't work because from the implied question, I'm trying to get someone who knows how, to help me with the code
" to calculate the # of days late (dayslate)(# of days from the duedate to the current date".The table does, in fact, have the necessary fields in it because, as a neophite, I know that the program can't work otherwise.
"calculate the # of days late (dayslate)(# of days from the duedate to the current date"& insert that value into that same database. How about it? Do you know how & are you willing to disclose that knowledge ?
// calculations to determine number of days late current date minus duedate
function networkdays($s, $e)
{
// If the start and end dates are given in the wrong order, flip them.
if ($s > $e)
return networkdays($e, $s);
// Find the day of the week for the two dates.
$sd = date("d", $s);
$ed = date("d", $e);
// Find the number of weeks between the dates.
$w = floor(($e - $s)/(86400*7)); # Divide the difference in the two times by seven days to get the number of weeks.
if ($ed >= $sd) { $w--; } # If the end date falls on the same day of the week or a later day of the week than the start date, subtract a week.
// Calculate net working days.
$nwd = max(6 - $sd, 0); # If the start day is Saturday or Sunday, add zero, otherewise add six minus the weekday number.
$nwd += min($ed, 5); # If the end day is Saturday or Sunday, add five, otherwise add the weekday number.
$nwd += $w * 5; # Add five days for each week in between. }
return $nwd;
}
$duedate = strtotime("1 January 2010"); // duedate
$currdate = strtotime("13 December 2010"); // current date
$db = mysql_connect("localhost","root","");
$db = mysql_select_db("oodb");
$query = "SELECT id, charges, datediff(curdate(),duedate) as dayslate, tax FROM oocust Where WHERE payrec = 'R' AND pd = ' '";
$result = mysql_query($query)) or die ("could not execute query at line 4"); // see note
while ($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
$days_late = ($row['dayslate'] > 0)?$row['dayslate'] . " days":'N/A';
echo "<p> Charges: " . $stat['charges'] . " Due Date: " . $row['duedate'] .
" Late: $days_late Tax: " . $row['tax'] . "</p>";
// ADD YOUR UPDATE STATEMENTS TO RECORD $id HERE, within the while loop.
}
returns expr1 – expr2 expressed as a value in days from one date to the other.
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\invoice\invcalc.php on line 5
could not execute query at line 4:
<?php
$stat = mysql_connect("localhost","root","");
$stat = mysql_select_db("oodb");
$query = "SELECT invnum FROM oocust Where WHERE id = '$id'";
$stat = mysql_fetch_assoc(mysql_query($query));
echo $stat["invnum"];
$result= mysql_query("select * from oocust");
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$dayslate=$row['dayslate'];
$charges=$row['charges'];
$duedate=$row['duedate'];
$tax=$row['tax'];
$tax = $charges * .06;
// *****************
// $db = mysql_connect("localhost","root","");
$db = mysql_select_db("oodb");
$query = "SELECT id, charges, datediff(curdate(),duedate) as dayslate, tax FROM oocust Where WHERE payrec = 'R' AND pd = ' '";
$result = mysql_query($query) or die ("could not execute query at line 4");
// see note while ($row = mysql_fetch_assoc($result))
{
$id = $row['id'];
$days_late = ($row['dayslate'] > 0)?$row['dayslate'] . " days":'N/A';
echo "<p> Charges: " . $stat['charges'] . " Due Date: " . $row['duedate'] . " Late: $days_late Tax: " . $row['tax'] . "</p>";
// ADD YOUR UPDATE STATEMENTS TO RECORD $id HERE, within the while loop.
$sql = "UPDATE oocust SET
tax = '$tax', dayslate = '$dayslate'
WHERE id='$id'";
// *******************
}
mysql_query($sql) ;
$err=mysql_error();
if($err!=""){
echo "Error in $sql: $err\n";
}
}
echo "Invoice Prep completed";
?>
Charges: 160.00 Due Date: 02/07/2011 Days Late: N/A Tax: 9.6
Charges: 88.00 Due Date: 4/15/2011 Days Late: N/A Tax: 5.28
Charges: 10.00 Due Date: 1/25/2011 Days Late: N/A Tax: 0.6
Charges: 300.00 Due Date: 4/15/2011 Days Late: N/A Tax: 18
Charges: 60.00 Due Date: 2/21/2011 Days Late: N/A Tax: 3.6
Charges: 50.00 Due Date: 5/5/2010 Days Late: N/A Tax: 3
Charges: 31.80 Due Date: 4/13/2011 Days Late: N/A Tax: 1.908
<?php
$stat = mysql_connect(localhost,root,"");
$stat = mysql_select_db(oodb) or die( "Unable to select database");
$query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '";
$stat = @mysql_fetch_assoc(mysql_query($query));
$result= mysql_query("select * from oocust");
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$tax = $row['tax'];
$charges = $row['charges'];
$tax = $charges * .06;
$days_late = ($row['dayslate'] > 0)?$row['dayslate'] . " days":'N/A';
echo "<p> Charges: " . $row['charges'] . " Due Date: " . $row['duedate'] . "
Days Late: $days_late Tax: $tax</p>";
}
$sql = "UPDATE oocust SET
tax = '$tax', dayslate = '$days_late'
WHERE id='$id'";
mysql_query($sql) ;
$err=mysql_error();
if($err!=""){
echo "Error in $sql: $err\n";
echo "Invoice Prep completed";
}
?>