Jump to content

while loops


bscotyb

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/261446-while-loops/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.