husslela03 Posted October 30, 2009 Share Posted October 30, 2009 hello, I have this code below that is attached to a flat file like this: Email:LastName:FirstName:Assignment1,100:Assignment2,100:Quiz1,50 [email protected]:Doe:John:85:93:45 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. Link to comment https://forums.phpfreaks.com/topic/179631-help-with-calculations-on-a-flat-text-file/ Share on other sites More sharing options...
akitchin Posted October 30, 2009 Share Posted October 30, 2009 it isn't really a straightforward calculation when your weights are 100, 100, and 50. what do those weights actually mean? Link to comment https://forums.phpfreaks.com/topic/179631-help-with-calculations-on-a-flat-text-file/#findComment-947844 Share on other sites More sharing options...
husslela03 Posted October 30, 2009 Author Share Posted October 30, 2009 i'm doing a grade management system. The weights actually mean, that a Quiz is worth 50 points and the Assignment is worth 100 points which is in the first row... then the consecutive rows are students of what they actually received on the assignment.. i need to calculate their score for that assignment and then at the end of each row I need to calculate their overall averages. Link to comment https://forums.phpfreaks.com/topic/179631-help-with-calculations-on-a-flat-text-file/#findComment-947857 Share on other sites More sharing options...
akitchin Posted October 30, 2009 Share Posted October 30, 2009 well, i'll give you the math, which you can try to put into your script: 1. keep track of how much each document is worth. a handy way of doing this would be in the format: $grade_weights[DOCUMENT_NUMBER] => DOCUMENT_POINT_WORTH 2. put the total number of points possible into a local variable. if you stored the weights in an array as per #1, this is merely a matter of using array_sum(). 3. here you have a few options. you can either: a) divide each item in the $grade_weights array by the total calculated in #2, or b) leave the array as-is and begin parsing through each student's line. 4. depending on whether you went the 3a or the 3b route, for each student: a) multiply each document grade by the corresponding percent coefficient in $grade_weights, and simply sum those numbers, or b) multiply each document grade by the point weight, divide by the total from #2, and sum those numbers. a) and b) routes are completely arbitrary, as the only difference between them is the order of operations. try to plug that math into your script and come back if you run into any troubles. Link to comment https://forums.phpfreaks.com/topic/179631-help-with-calculations-on-a-flat-text-file/#findComment-947870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.