bscotyb Posted April 16, 2012 Share Posted April 16, 2012 i am trying to pull a .txt file for a class assignment and it is pulling everything except for line 1 any suggestions would be great 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> txt.file 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 php file: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = $_POST ['paintfile']; $nextDay = $_POST['nextDay']; $paintFile = fopen("weeklyDataBoles.txt","r"); $week = fgets($paintFile); $total = 0; for ($count = 1; $count <=8; $count = $count +1) { $nextDay = fgets($paintFile); $total = $total + $nextDay; } $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> Quote Link to comment https://forums.phpfreaks.com/topic/261045-missing-line-from-my-txt-file/ Share on other sites More sharing options...
silkfire Posted April 16, 2012 Share Posted April 16, 2012 Which line is missing and can you please show us your text file? Quote Link to comment https://forums.phpfreaks.com/topic/261045-missing-line-from-my-txt-file/#findComment-1337860 Share on other sites More sharing options...
batwimp Posted April 16, 2012 Share Posted April 16, 2012 You're not getting your first line because fgets() reads and entire line, then moves the line pointer ahead one. So this line: $week = fgets($paintFile); reads the first line of your text file, doesn't do anything with it, and moves the pointer ahead one. So when you encounter this line: $nextDay = fgets($paintFile); the line pointer is already on line 2, which you are using. And I'm not sure this code is doing what you want it to. Since fgets() reads and entire line, you are adding up your line numbers and not the dollar amounts. Quote Link to comment https://forums.phpfreaks.com/topic/261045-missing-line-from-my-txt-file/#findComment-1337862 Share on other sites More sharing options...
bscotyb Posted April 16, 2012 Author Share Posted April 16, 2012 it is missing line 1 weeklyDataBoles.txt txt.file 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 Quote Link to comment https://forums.phpfreaks.com/topic/261045-missing-line-from-my-txt-file/#findComment-1337864 Share on other sites More sharing options...
bscotyb Posted April 16, 2012 Author Share Posted April 16, 2012 ty very much!! Quote Link to comment https://forums.phpfreaks.com/topic/261045-missing-line-from-my-txt-file/#findComment-1337865 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.