Hi, I have checked the validity of the table and in
all 3 records "recur" ='Y', "payrec" ='p', values are in "duedate",
"datepaid" (type is DATE) and "periodic". I'm looping thru the data; var_dump() displays NULL NULL NULL, It seems that my DATEDIFF is flawed.
I've spent considerable time viewing forums, manuals, code types. How about some advice?
Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(0);
$servername = "localhost"; $username = "root";
$password = "cookie"; $dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{ die("Connection failed: " . $conn->connect_error); }
// ==================================================
$sql = "SELECT recur, periodic, pd, payrec, duedate, datepaid,
DATEDIFF(CURDATE(),duedate) AS dayslate
FROM testbl WHERE recur = 'Y' && payrec = 'P'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc()) // ****3 records *****
{
// ***************************************************
var_dump($dayslate); // NULL NULL NULL
// ***************************************************
if ($dayslate > 0)
{
if($dayslate > 120)
{$pastdue = "PAST DUE";}
if($periodic == 1)
{ $duedate = date('Y-m-d', strtotime('+4 week')) ."\n"; }
if($periodic == 6)
{ $duedate = date('Y-m-d', strtotime('+25 week')) ."\n"; }
$pd = 'P'; $daylate = 0;
// ==================================================
$sql = "UPDATE testbl SET
pd = '$pd',
duedate = '$duedate',
$datepaid = 'NOW()',
dayslate = '$dayslate'
WHERE dayslate = 0";
if ($conn->query($sql) === TRUE)
{ echo "Record updated successfully"; }
else
{ echo "Error updating record: " . $conn->error; }
$conn->close();
}
}
}
// header( "refresh:3;url='http://localhost/invoice/autolist.php'");
?>
Bookmarks