这是一个示例,在您的代码中,您将值视为字符串:
<?php
//Example values, simulate a request
$_REQUEST['id']='25';
$_REQUEST['ass1']='17';
$_REQUEST['ass2']='28';
$_REQUEST['ass3']='32';
//Get and check the values from the user
$values=array();
$values['id'] = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id']))?$_REQUEST['id']:0;
$values[1] = (isset($_REQUEST['ass1']) && is_numeric($_REQUEST['ass1']))?$_REQUEST['ass1']:0;
$values[2] = (isset($_REQUEST['ass2']) && is_numeric($_REQUEST['ass2']))?$_REQUEST['ass2']:0;
$values[3] = (isset($_REQUEST['ass3']) && is_numeric($_REQUEST['ass3']))?$_REQUEST['ass3']:0;
$values['t'] = 3;
//one line add the variables together then devide by 3 and then round down or up depending on whats closest
$values['average'] = round(( ($values[1] + $values[2] + $values[3]) / $values['t'])); //26
$q = "UPDATE grades SET ass1={$values[1]}, ass2={$values[2]}, ass3={$values[3]}, grade={$values['average']} WHERE id = {$values['id']}";
echo $q;
//UPDATE grades SET ass1=17, ass2=28, ass3=32, grade=26 WHERE id = 25
?>