Quote:
Code:
if ($answer==$ganswer) {
$whichscore = 'gscore';
}elseif ($answer==$sanswer) {
$whichscore = 'sscore';
}elseif ($answer==$hanswer) {
$whichscore = 'hscore';
}else{
$whichscore = 'rscore';
}
|
I may be seeing things strangely, but if g, s, h, and rscore are all variables, shouldn't they be prefixed with "$"?
Like this?
PHP Code:
if ($answer == $ganswer){
$whichscore = $gscore;
} elseif ($answer == $sanswer){
$whichscore = $sscore;
} elseif ($answer == $hanswer){
$whichscore = $hscore;
} else {
$whichscore = $rscore;
}
If the *score fields contain any thing I'm thinking that they should be called as variables, so that when you make $whichscore equivalent to them, then $whichscore would be == the information that they contain. As it sits now with what you provided, then $whichscore is equivalent not to the information that the *score fields contain, but to their string names only.
So assuming that:
PHP Code:
$gscore = 1;
$sscore = 2;
$hscore = 3;
$rscore = 4;
Then with your code, $whichscore would output the name (whichever meets the if statement criteria). Using the one I suggest, the if $answer doesn't equal any of the *answer comparators, then $whichscore will contain and output "4".