so i have a series of problems ive been working on and the last one is giving me problems. I have a script that reads a text file does some stuff with it and then displays it. that all works just fine now i have to add a fwrite to a external text file. basically the fget brings it in does some calculations and displays them line by line, I need to do the the same with fwrite but all it will do is write from the first line. heres my code
[php]
Display Monthly Sales: "."
"; displayData($fp); function displayData($fp){ //define an array to store data while(!feof($fp)){ // read the current line $info = fgetcsv($fp, 250, ','); // add dataa only if data is nonempty if ($info[0] !=""){ // read the date into a variable $month = $info[0]; $sales =$info[1]; $rent =$info[2]; $wages =$info[3]; $supplies =$info[4]; }// end if // echo"Month: ".$month.", Sales: ".$sales." Rent ".$rent."Wages:".$wages."Supplies:".$supplies."
\n"; echo"Month: Rent: Sales: Wages: Supplies: "."
\n"; echo "".$month.""." ".$sales." ".$rent." ".$wages." ".$supplies."
\n"; echo "
\n"; $fw = fopen("problem4.txt", "w"); $total_cost=$rent+$wages+$supplies; $operating_income = $sales-$total_cost; $net_income= $operating_income*.60; // use fwrite() to write data // syntax: fwrite('file_pointer, "string"); fwrite($fw, "Month: Sales: Total Cost: Operating Income: Net Income:"."\n"); fwrite($fw, $month." ".$sales." ".$total_cost." ".$operating_income." ".$net_income."\n" ); }//end while } ?>
[/php]
I really only need the first fwrite line to write once but i need the second one to write each line that it had read. so confused!!!