Parsing from a php file, line by line

Discussion in 'PHP' started by blackburn2413, Mar 28, 2011.

  1. #1
    Hey everyone, I am working on a project for ranking employees in my job. Basically I have a .csv output file that lists the revenue results for each person for the week.

    Basically what I want to do is have a field where I can upload the weekly report then the script reads that file and parses the data. Then I would use the data to award points to each person.

    So basically I would take that parsed data from each field and write to my sql database.

    so... :
    
    if ($revenue >= '1500') { ##query to write value to sql database ## }
    if ($close_rate >= '0.15') { ##query to write value to sql database ## }
    if ($hoursworked>= '32') { ##query to write value to sql database ## }
    
    
    
    Code (markup):
    In the csv file each line if for a different employee, so I would run the script in a loop to go through all the employees.

    Thats the goal so does anyone have an idea of what functions or code I can use to accomplish this? Any help would be appreciated! Thanks
     
    blackburn2413, Mar 28, 2011 IP
  2. blackburn2413

    blackburn2413 Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    so did some further research and found this code from php.net

    
    <?php
    $row = 1;
    if (($handle = fopen("test.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            echo "<p> $num fields in line $row: <br /></p>\n";
            $row++;
            for ($c=0; $c < $num; $c++) {
                echo $data[$c] . "<br />\n";
            }
        }
        fclose($handle);
    }
    ?>
    
    Code (markup):
    That will display the contents from a csv file so no reason I cant modify that so instead of echo'ing $data[] near the end that it compares that value in the 'if' statements like I mentioned...

    back to work :D
     
    blackburn2413, Apr 1, 2011 IP
  3. zeekapitein

    zeekapitein Active Member

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    zeekapitein, Apr 2, 2011 IP