bscotyb Posted April 16, 2012 Share Posted April 16, 2012 I am trying to use this weeklyReport1Boles.html: <html> <head> <title>Weekly Report</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Weekly Report</h1> <p> <form action = "weeklyReport1Boles.php" method = "post" > <p> <input type = "submit" value = "Display the Report" /> </p> </form> </body> </html> TO PULL data from weeklyDataBoles.txt lines 1-8 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 THE RESULTING WEB PAGE SHOULD BE: Weekly Report TOTAL INCOME FROM PAINT CONTRACTS: $0.00 AVG DAILY INCOME FROM PAINT CONTRACTS: $0.00 NUMBER OF DAYS with NO INCOME: . MY PHP CODE IS: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); $total = 0; for ($count= 1; $count <=7; $count = $count +1) { $nextDay = fgets($weeklyDataBoles); $total = $total + $nextDay; } fclose($weeklyData); $avgDailyIncome = $total/7; print("<p>TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."</p>"); print("<p>AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."</p>"); print("<p>NUMBER OF DAYS with NO INCOME: $badDays.</p>"); ?> </body> </html> THE AVERAGES ARE BASED ON ONE WEEK OR SEVEN DAYS, WHY CANT I OPEN THE FILE AND GET THE PROGRAM TO READ IT, I AM A STUDENT AND VERY, VERY, VERY BAD AT THIS, MAKES ME CRAZY CAUSE I REALLY LOVE IT Quote Link to comment https://forums.phpfreaks.com/topic/261006-reading-a-txt-file/ Share on other sites More sharing options...
gizmola Posted April 16, 2012 Share Posted April 16, 2012 Please, no more caps. Just makes your post harder to read, and will cause people that would otherwise consider helping you to skip your question. Off the top, you do this: $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); Notice that you open a file and assign the file handle to a variable named $paintfile. Then you try and fgets() from an entirely different variable. Start there. Quote Link to comment https://forums.phpfreaks.com/topic/261006-reading-a-txt-file/#findComment-1337693 Share on other sites More sharing options...
bscotyb Posted April 16, 2012 Author Share Posted April 16, 2012 sorry about the caps new to this and desperately trying to understand, ty for understanding Quote Link to comment https://forums.phpfreaks.com/topic/261006-reading-a-txt-file/#findComment-1337694 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.