bscotyb Posted April 22, 2012 Share Posted April 22, 2012 i am a student and trying to figure out why this is not working for me i am trying to pull from my .txt file and add the lines. $numOrders should be 20 and $numCopies should be 52. it keeps telling me --Warning: feof() expects parameter 1 to be resource, string given on line 25. i really am having big trouble trying to understand how to use the while loop for this. any help would be great. here is my html code <html> <head> <title>Software1</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>SOFTWARE ORDERS: REPORT</h1> <form action = "software1Boles.php" method = "post" > <p><input type = "submit" value = "Display the Report" /></p> </form> </body> </html> my php code <?php $totalCopies = $_POST['totalCopies']; $totalOrders = $_POST['totalOrders']; $nextOrder = $_POST['nextOrder']; $totalCopies = 0; $totalOrders = 0; $orderFile = fopen("ordersBoles.txt", "r"); $nextOrder = fgets ($orderFile); while (!feof($nextOrder)) { list($totalCopies, $totalOrders) = explode (":", $nextOrder); if ($totalCopies >=1 and $totalCopies >=1) { $totalCopies = $totalCopies + $nextOrder; $totalOrder = $totalOrder + $nextOrder; } $nextOrder = fgets($orderFile);} fclose($orderFile); print ("<h1>SOFTWARE ORDERS: REPORT</h1>"); print ("<p>TOTAL COPIES ORDERED: $totalCopies</p>"); print ("<p>TOTAL ORDERS: $totalOrders</p>"); ?> </body> </html> and my .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 anything you can give me would help alot, thanks Quote Link to comment https://forums.phpfreaks.com/topic/261446-while-loops/ Share on other sites More sharing options...
xyph Posted April 22, 2012 Share Posted April 22, 2012 Check the manual on what fgets returns. Whatever it returns, will be the value of $nextOrder. You should also check what kind of argument feof expects. The fgets manual link has an example that provides an alternate way of doing this. Quote Link to comment https://forums.phpfreaks.com/topic/261446-while-loops/#findComment-1339690 Share on other sites More sharing options...
bscotyb Posted April 22, 2012 Author Share Posted April 22, 2012 thank you Quote Link to comment https://forums.phpfreaks.com/topic/261446-while-loops/#findComment-1339697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.