help with calculations on a flat text file


Posted on 16th Feb 2014 07:03 pm by admin

hello,
I have this code below that is attached to a flat file like this:
Email:LastName:FirstName:Assignment1,100:Assignment2,100:Quiz1,50
someone@email.com:Doe:John:85:93:45
Did you know?Explore Trending and Topic pages for more stories like this.

Here is the code:
<?php
$row=1;
$handle= fopen($full_file,'r');
$heading=True;
echo '<table>';
$data=fgetcsv($handle,1024,":");
echo '<tr>';
foreach ($data as $cell)
{
echo '<th>' .$cell. '</th>';
}

echo '<th>Overall Average</th>';
echo '</tr>';

while (($data=fgetcsv($handle,1024,":")) !==FALSE)
{
echo '<tr>';
foreach($data as $cell)
{
$average=$cell/100;
echo '<td width="50">' .$cell. ' ' .$average. '</td>';


}

//echo '<td></td>';


}
if ($row==1)
{
$heading=False;
}
$row++;
echo '</tr>';



echo '</table>';
fclose($handle);
?>

what i need to do with this code, is have an extra column added at the end where is averages out the student's scores, based on the weight of the grade that is located on row 1 and delimited by a ",".

Please help.
No comments posted yet

Your Answer:

Login to answer
67 Like 32 Dislike
Previous forums Next forums
Other forums

Custom array sort? asc then desc
Any ideas how I could sort this array? I've been trying for a while. Maybe with usort, but I have no

BI in Upstream Production operations
Appreciate if you can assist in the following areas:
1) Examples of life before and after BI i

using explode() to fill in checkboxes
Hi

I have a field stored in a table that contains regions in the UK separated by commas. Ther

Modal Popup Help
Hi guys, I have a modal popup with an iframe. How can i send data from a label or textbox to the ifr

help connecting a form to php and then emailing the form
Ok. So, I made a form, and I need help to where when submitted, I get an email with the submitted de

Require select-option functionality in Module Pool Programming
Hi Gurus,

I am doing a development by Module Pool on Warehouse Management. For that devel

simple script won't work. Please help
I'm new to php, and I am having trouble displaying a simple script in my web browser. My php code ex

WELCOME SCREEN
first of all let me tell you what does my script do,

it´s a very simple query to show a e

PHP IMAGE UPLOAD SCRIPT
Hi for the last week i have been looking for scripts that will upload a photo to a certain folder wh

* Gridview and Detailsview in UpdatePanel, insert mode problem
I have a GridView and DetailsView working together. When a record from Gridview is selected, Detail

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash