MadTechie Posted October 29, 2009 Share Posted October 29, 2009 try this <form method='post' action=''> <?php $average= 0; $values = array('grades' => array_fill(0, 10, 0)); if(isset($_POST['grades'])){ $values = $_POST; $grade=$_POST['grades']; $total = 0; foreach($grade as $grades){ $total += $grades; } $average = $total/count($_POST["grades"]); } for($n=0;$n<10;$n++){ echo "Grade ".($n+1).":<input name=\"grades[$n]\" type=\"text\" value = \"{$values['grades'][$n]}\" />"; } ?> <input type='Submit' name='Submit' value="Submit" /> </form> <?php echo getGrades($average); function getGrades($grade){ if ($grade >= 89.5){//is A return 'A'; }elseif ($grade >= 79.5){ return 'B'; }elseif($grade >= 69.5){ return 'C'; }elseif ($grade >= 59.5){ return 'D'; } return 'F'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947478 Share on other sites More sharing options...
kaveman50 Posted October 29, 2009 Share Posted October 29, 2009 . Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947484 Share on other sites More sharing options...
Thethug Posted October 29, 2009 Author Share Posted October 29, 2009 It just says F at the bottom and won't output anything. Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947486 Share on other sites More sharing options...
MadTechie Posted October 29, 2009 Share Posted October 29, 2009 change echo getGrades($average); to if(isset($_POST['grades'])){ echo getGrades($average); } Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947487 Share on other sites More sharing options...
Thethug Posted October 29, 2009 Author Share Posted October 29, 2009 Awesome, that displayed the correct letter. Is there a way to also display the percent? Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947490 Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 just display the $average variable Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947491 Share on other sites More sharing options...
Thethug Posted October 29, 2009 Author Share Posted October 29, 2009 Awesome. Thanks guys for the help! Quote Link to comment https://forums.phpfreaks.com/topic/179449-solved-array-help/page/2/#findComment-947494 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.