PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 6, 2022

[FIXED] How to count the quantity of rows in CSV where in column find the today's date?

 October 06, 2022     csv, php, statistics     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing