while loop

i am trying to pull the info from my txt. file and get my php to process it so it shows up when i run the web page. The web page should display the name and how many copies altogether from the txt. file there are. i have been trying all day to finish this assignment for school, any help would be greatly appreciated.

html

Software1

SOFTWARE ORDERS: REPORT

php

<?php $multipleOrders = 0; $linuxCopies = 0; $macintoshCopies = 0; $windowsCopies = 0; $orderFile = fopen("ordersBoles.txt", "r"); $nextOrder = fgets ($orderFile); while (!feof($orderFile)) { list($os,$copies) = split (":", $nextOrder); { if ($os == "Linux") { $linuxCopies = $copies + 1; } if ($os == "Macintosh") { $macintoshCopies = $copies + 1; } if ($os == "Windows" ) { $windowsCopies = $copies + 1; } if ($os == "Multiple") { $multipleCopies = $copies + 1; } } $nextOrder = fgets ($orderFile); } fclose($orderFile); print ("

SOFTWARE ORDERS: REPORT

"); print ("

ORDERS FOR MULTIPLE COPIES: $multipleOrders

"); print ("

LINUX COPIES ORDERED: $linuxCopies

"); print ("

MACINTOSH COPIES ORDERED: $macintoshCopies

"); print ("

WINDOWS COPIES ORDERED: $windowsCopies

"); ?>

txt. file

1 Linux:1
2 Macintosh:1
3 Windows:1
4 Macintosh:1
5 Macintosh:2
6 Linux:5
7 Macintosh:10
8 Windows:10
9 Macintosh:1
10 Windows:1
11 Windows:1
12 Linux:1
13 Macintosh:5
14 Linux:4
15 Windows:1
16 Macintosh:1
17 Windows:1
18 Linux:2
19 Macintosh:2
20 Windows:1
21

Well, you have no error checking in your program. First, does the file get opened? If not, it might be spelled wrong. Caps are important. Also, is the file’s line numbers actually in the file? I mean, the first example you showed us is “1 Linux:1” … So, the first value would be “1 Linux” not “Linux”. This would not work.

You can use the “echo” command for debugging. Just after getting the line, just “echo $nextOrder” and see what you get out of the file. Then, you have a start to where you need debugging done…

Look into it and let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service