[SOLVED] Reading and counting seperate values from a text fi

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rosszor
Forum Newbie
Posts: 1
Joined: Sat Nov 08, 2008 4:41 pm

[SOLVED] Reading and counting seperate values from a text fi

Post by Rosszor »

I have a homework assignment asking me to read two kinds of input from a file. An Operating system name, and a value for the number of copies ordered. I have to use a While statement.
Basically I need to count up the number of orders total (how many people ordered) total copies sold (the number of orders per person).

Below is what I have so far.... and below that is a copy of the .txt file I'm reading from.
But it's not working.

This is one of those simple things that I'm just missing, I know it :banghead:



Code: Select all

<?php
        $totalCopies = 0;
        $totalOrders = 0;
 
        $orderFile = fopen("orders.txt", "r");
        $nextOrder = fgets ($orderFile);
        
        while (!feof ($orderFile))  
        {
            list ($order, $copies)  = split (":", $nextOrder);
                $totalOrders = $order + $totalOrders;
                $totalCopies = $copies = $totalCopies;
        
                $nextOrder = fgets($orderFile);
        }
        fclose ($orderFile);
 
        print ("<h1>SOFTWARE ORDERS: REPORT</h1>");
        print ("<p>TOTAL COPIES ORDERED: $totalCopies</p>");
        print ("<p>TOTAL ORDERS: $totalOrders</p>");
    ?>



Linux:1
Macintosh:1
Windows:1
Macintosh:1
Macintosh:2
Linux:5
Macintosh:10
Windows:10
Macintosh:1
Windows:1
Windows:1
Linux:1
Macintosh:5
Linux:4
Windows:1
Macintosh:1
Windows:1
Linux:2
Macintosh:2
Windows:1



****Eh, nevermind. I got it. :)*****
Post Reply