Issue
I have a file CSV: https://metalval.ru/account/data/stat/all.csv. Needs to print the sum (count) of rows where is current date ($today) and count of rows where current week to show in stat's dashboard the quantity of orders today and on this week.
Some example is a test code in work:
<?php
if (($handle = fopen("https://metalval.ru/account/data/stat/all.csv", "r")) !== FALSE) {
$today = date("d.m.Y");
$row = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($data[2] == $today) {
$row++;
}
else {
$row = 0;
}
}
fclose($handle);
echo $row;
}
?>
Solution
I just had to remove the else condition, because every time that $data[2]
was different than $today
the counter was reseted.
if (($handle = fopen("https://metalval.ru/account/data/stat/all.csv", "r")) !== FALSE) {
$today = date("d.m.Y");
$row = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($data[2] == $today) {
$row++;
}
}
fclose($handle);
echo $row;
}
Answered By - Victornfb Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.