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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.