help please

am a student trying to figure this out and no matter what i do it is not coming up correctly
I am trying to use this weeklyReport1Boles.html:

Weekly Report

Weekly Report

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: .

ny 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("

TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."

"); print("

AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."

"); print("

NUMBER OF DAYS with NO INCOME: $badDays.

"); ?>

I am very inexperienced and would love any help offered. Please remember I am a student so my code may be in the shambles already. ty

What errors are you getting? Is this all of the code? I’m seeing a lot of variables that are never declared and variables declared for what appears to be no reason–for example: $year = fgets(–undeclared varible–) then $year nevr shows up again, but you have $nextDay perform the same task in whic $nextDay is the same as $year…

What’s more I’m a little uncertain what you are trying to do… is each line in the txt file the daly income? In which you’re wanting to addthem up display the total, get and the display the average and count any lines tha contain no income and display that? If this is the case:

$file = fopen(“weeklyDataBoles.txt”, “r”);
$lines = array();
for($I = 1, $I <= 7, $i++) {
$lines[] = fgets($file);
}
$linesTotal = 0;
$avgBad = 0;
foreach ($lines as $k => $v) {
$linesTotal = ($linesTotal + $v);
if ($v == “0.00”) {
$avgBad = ($avgBad++);
}
}
$avg = ($linesTotal / 7);

Then simply print $linesTotal for total income, $avg for the average, and $avgBad for the bad days.

Sponsor our Newsletter | Privacy Policy | Terms of Service