View Full Version : Need help finishing...
Chris M
06-15-2003, 03:35 PM
The score grabbing works, but now I need the the values in the "gscore,sscore,hscore and rscore" fields;)
So far, they return:
gscore
sscore
hscore
rscore
I am not sure what type of field they should be (I have them set as INT:confused:), and they are a point value, with gscore being 4 and sscore being 1...
This code is what needs to be modified to get the value (everything else works:D):)
$score = $DB_site->query_first("SELECT '$whichscore' FROM *tablename*_questions WHERE qid='$theqid'");
if ($bbuserinfo['usergroupid']==2)
{
$DB_site->query("UPDATE user SET question1='$theqid',score1='$score[$whichscore]' WHERE userid='$bbuserinfo[userid]'");
}
Any help?:)
Satan
Chris M
06-16-2003, 07:14 AM
Please can anyone help?
I really need to get this finished...
Satan
Cloudrunner
06-16-2003, 07:40 AM
$score = $DB_site->query_first("SELECT '$whichscore' FROM *tablename*_questions WHERE qid='$theqid'");
if ($bbuserinfo['usergroupid']==2)
{
$DB_site->query("UPDATE user SET question1='$theqid',score1='$score[$whichscore]' WHERE userid='$bbuserinfo[userid]'");
}
Any help?:)
Satan
Try changing the code thusly:
$score = $DB_site->query_first("SELECT whichscore FROM *tablename*_questions WHERE qid = '"
.$theqid
."'");
if ($bbuserinfo['usergroupid'] == 2){
$DB_site->query("UPDATE user SET question1 = '"
.$theqid
."', score1 = '"
.$score[whichscore]
."' WHERE userid = '"
.$bbuserinfo[userid]
."'");
}
Of course I am assuming that $whichscore is a column name and not a variable that has been pre-defined previously in the code. If my assumption is correct then removing the "$" effectively turns whichscore into an array identifier.
If on the other-hand, $whichscore IS a variable, then I would do the code like this:
$score = $DB_site->query_first("SELECT '"
.$whichscore
."' FROM *tablename*_questions WHERE qid = '"
.$theqid
."'");
if ($bbuserinfo['usergroupid'] == 2){
$DB_site->query("UPDATE user SET question1 = '"
.$theqid
."', score1 = '"
.$score[$whichscore]
."' WHERE userid = '"
.$bbuserinfo[userid]."'");
}
Lemme know if this helps or if I'm just blowing smoke up my own arse. I could probably figure it out with you if I had abit more reference code to go by... ;)
p.s. I always break out of quotes when calling variables, just for my own piece of mind. I know you don't have to, but I do unless I'm required to not do it.
Chris M
06-16-2003, 08:04 AM
Aha thanks...
Yes $whichscore is a earlier defined variable, via this code:
if ($answer==$ganswer) {
$whichscore = 'gscore';
}elseif ($answer==$sanswer) {
$whichscore = 'sscore';
}elseif ($answer==$hanswer) {
$whichscore = 'hscore';
}else{
$whichscore = 'rscore';
}
I will try your code, but if it doesn't work, all I can suggest is that the $answer variable is not being intval'ed properly;)
Thanks - I'll try this:)
Satan
Chris M
06-16-2003, 08:28 AM
:(
Unfortunately the code still returns "gscore" , "hscore", "sscore" and "rscore":(
Satan
Cloudrunner
06-16-2003, 08:29 AM
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?
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:
$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".
Chris M
06-16-2003, 08:34 AM
Hmm...I never thought of that - I shall try, thanks:D:)
Satan
Cloudrunner
06-16-2003, 08:40 AM
np...lemme know.
Chris M
06-16-2003, 08:53 AM
Ok...That didnt work...
But then I had an idea - Why query the database for "$whichscore" if the score value is already defined - So I was thinking:
if ($answer == $ganswer){
$score = $gscore;
} elseif ($answer == $sanswer){
$score = $sscore;
} elseif ($answer == $hanswer){
$score = $hscore;
} else {
$score = $rscore;
}
$gscore = 4;
$hscore = 3;
$rscore = 2;
$sscore = 1;
if ($bbuserinfo['usergroupid'] == 2){
$DB_site->query("UPDATE user SET question1 = '"
.$theqid
."', score1 = '"
.$score ."'
WHERE userid = '"
.$bbuserinfo[userid]."'");
}
Think I should try it?:)
Edit: It didn't work:(
Satan
Chris M
06-16-2003, 08:59 AM
Ah...
If the answer is a numerical value, $answer returns the numerical value of that answer (i.e. if the first answer was 93, $answer returns 93)
If the answer is a non-numerical value, $answer returns 0:(
Satan
Cloudrunner
06-16-2003, 09:07 AM
try moving the defined variables above the compare code:
$gscore = 4;
$hscore = 3;
$rscore = 2;
$sscore = 1;
if ($answer == $ganswer){
$score = $gscore;
} elseif ($answer == $sanswer){
$score = $sscore;
} elseif ($answer == $hanswer){
$score = $hscore;
} else {
$score = $rscore;
}
if ($bbuserinfo['usergroupid'] == 2){
$DB_site->query("UPDATE user SET question1 = '"
.$theqid
."', score1 = '"
.$score ."'
WHERE userid = '"
.$bbuserinfo[userid]."'");
}
and then add this to just below the compare code to see what is contained in $score.
echo $score;
so it would end up looking like this:
$gscore = 4;
$hscore = 3;
$rscore = 2;
$sscore = 1;
if ($answer == $ganswer){
$score = $gscore;
} elseif ($answer == $sanswer){
$score = $sscore;
} elseif ($answer == $hanswer){
$score = $hscore;
} else {
$score = $rscore;
}
echo $score;
if ($bbuserinfo['usergroupid'] == 2){
$DB_site->query("UPDATE user SET question1 = '"
.$theqid
."', score1 = '"
.$score ."'
WHERE userid = '"
.$bbuserinfo[userid]."'");
}
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.