Code below is not working. It reads from a .txt file with strings of data including lines like the following:
Windows:2
Where first variable is the operating system and the second is the amount of copies ordered.
It’s supposed to count the number of orders that request more than one copy, the number of copies of Linux software ordered, the number of copies of Macintosh software ordered, and the number of copies of Windows software ordered. The numbers aren’t coming out correctly and I cannot figure out why.
Software2<?php
$multipleOrders = 0;
$linuxCopies = 0;
$macintoshCopies = 0;
$windowsCopies = 0;
$orderFile = fopen("orders.txt", "r");
$nextOrder = fgets ($orderFile);
while(!feof($orderFile))
{
list($operatingSystem, $numCopies) =
explode(":", $nextOrder);
if($numCopies > 1)
{
$multipleOrders = $multipleOrders + 1;
}
if($operatingSystem == "Linux")
{
$linuxCopies = $linuxCopies + 1;
}
if($operatingSystem == "Macintosh")
{
$macintoshCopies = $macintoshCopies + 1;
}
if($operatingSystem == "Windows")
{
$windowsCopies = $windowsCopies + 1;
}
$nextOrder = fgets($orderFile);
}
fclose ($orderFile);
print ("<h1>SOFTWARE ORDERS: REPORT</h1>");
print ("<p>ORDERS FOR MULTIPLE COPIES: $multipleOrders</p>");
print ("<p>LINUX COPIES ORDERED: $linuxCopies</p>");
print ("<p>MACINTOSH COPIES ORDERED: $macintoshCopies</p>");
print ("<p>WINDOWS COPIES ORDERED: $windowsCopies</p>");
?>