gennemsnit af antal udfyldte felter
Hej eksperter.Jeg er ved at prøve at lave et scrip,som skal beregne summen, samt gennemsnittet af ti felter. men den skal kun beregne gennemsnittet ud fra de felter der er udfyldt. Det vil sige dem der er over 0
Jeg har prøvet mig lidt frem og er nu kommet frem til dette. Det udregner godt nok totalen men gennemsnittet driller.
Kan i hjælpe mig på rette vej?
her er koden:
if (isset($_POST['update_shooter'])) {
$tal1 = $_POST['res01'];
$tal2 = $_POST['res02'];
$tal3 = $_POST['res03'];
$tal4 = $_POST['res04'];
$tal5 = $_POST['res05'];
$tal6 = $_POST['res06'];
$tal7 = $_POST['res07'];
$tal8 = $_POST['res08'];
$tal9 = $_POST['res09'];
$tal10 = $_POST['res10'];
$tal012 = $_POST['res012'];
$tal022 = $_POST['res022'];
$tal032 = $_POST['res032'];
$tal042 = $_POST['res042'];
$tal052 = $_POST['res052'];
$tal062 = $_POST['res062'];
$tal072 = $_POST['res072'];
$tal082 = $_POST['res082'];
$tal092 = $_POST['res092'];
$tal102 = $_POST['res102'];
$tal11 = $tal1 + $tal2 + $tal3 + $tal4 + $tal5 + $tal6 + $tal7 + $tal8 + $tal9 + $tal10 + $tal012 + $tal022 + $tal032 + $tal042 + $tal052 + $tal062 + $tal072 + $tal082 + $tal092 + $tal102;
$count=0; {
if ($tal1 + $tal012 > 0){$count=$count+1;}
if ($tal2 + $tal022 > 0){$count=$count+1;}
if ($tal3 + $tal032 > 0){$count=$count+1;}
if ($tal4 + $tal042 > 0){$count=$count+1;}
if ($tal5 + $tal052 > 0){$count=$count+1;}
if ($tal6 + $tal062 > 0){$count=$count+1;}
if ($tal7 + $tal072 > 0){$count=$count+1;}
if ($tal8 + $tal082 > 0){$count=$count+1;}
if ($tal9 + $tal092 > 0){$count=$count+1;}
if ($tal10 + $tal102 > 0){$count=$count+1;}
if ($check['$count']) {
$tal12 = $tal1 + $tal2 + $tal3 + $tal4 + $tal5 + $tal6 + $tal7 + $tal8 + $tal9 + $tal10 + $tal012 + $tal022 + $tal032 + $tal042 + $tal052 + $tal062 + $tal072 + $tal082 + $tal092 + $tal102 / $count; }
else if ($check['$count'] = 0){
$tal12 = $tal1 + $tal2 + $tal3 + $tal4 + $tal5 + $tal6 + $tal7 + $tal8 + $tal9 + $tal10 + $tal012 + $tal022 + $tal032 + $tal042 + $tal052 + $tal062 + $tal072 + $tal082 + $tal092 + $tal102 / 1;
}}
dbquery("UPDATE ".DB_STAT1." SET name='".$_POST['name']."', `pos`='".$_POST['pos']."', dob='".$_POST['dob']."', height='".$_POST['height']."', weight='".$_POST['weight']."', hand='".$_POST['hand']."', res01='".$_POST['res01']."'+'".$_POST['res012']."', res02='".$_POST['res02']."'+'".$_POST['res022']."', res03='".$_POST['res03']."'+'".$_POST['res032']."', res04='".$_POST['res04']."'+'".$_POST['res042']."', res05='".$_POST['res05']."'+'".$_POST['res052']."', res06='".$_POST['res06']."'+'".$_POST['res062']."', res07='".$_POST['res07']."'+'".$_POST['res072']."', res08='".$_POST['res08']."'+'".$_POST['res082']."', res09='".$_POST['res09']."'+'".$_POST['res092']."', res10='".$_POST['res10']."'+'".$_POST['res102']."', total=".$tal11.", snit=".$tal12.", info='".$_POST['info']."', pic='".$_POST['pic']."', active='".$_POST['active']."', info_breaks='".$_POST['info_breaks']."' WHERE id='".$id."'");
redirect (FUSION_SELF.$aidlink, "script");
}