PDA

View Full Version : One last problem:(


Chris M
06-11-2003, 02:58 PM
I have fixed everything else, even Intvaling works:)

Now this code causes a "Resource id #13" error for the variable "$score" in this template:

<b>The question ID is: </b><u>$theqid</u>&nbsp;<i>AND</i> the Score is <font color="FF0000">$score</font> ($answer), $ganswer, $ranswer, $sanswer & $hanswer
^this is the "echomessage" template, used to check the output;)

Here is the PHP Code:
// ############################### start update3 ###############################
if ($action=="update3") {

$answer = intval($answer);

if ($answer==$ganswer) {
$whichscore = 'gscore';
}elseif ($answer==$sanswer) {
$whichscore = 'sscore';
}elseif ($answer==$hanswer) {
$whichscore = 'hscore';
}else{
$whichscore = 'rscore';
}

$score = $DB_site->query("SELECT '$whichscore' FROM *tablename*_questions WHERE qid='$theqid'");

if ($bbuserinfo['usergroupid']==2)
{
$DB_site->query("UPDATE user SET question3='$theqid',score3='$score' WHERE userid='$bbuserinfo[userid]'");
}

$goto="*filename*.php?s=$session[sessionhash]&action=4";
eval("standarderror(\"".gettemplate("echomessage")."\");");
}

I suspect it has something to do with the:
if ($answer==$ganswer) {
$whichscore = 'gscore';
}elseif ($answer==$sanswer) {
$whichscore = 'sscore';
}elseif ($answer==$hanswer) {
$whichscore = 'hscore';
}else{
$whichscore = 'rscore';
}

Can you see the problem, or suggest an alternative method?:)

I have attached a screenshot of the error itself;)

Satan

Xenon
06-11-2003, 04:10 PM
look in your script, $score is a $DB_site-query result, nothing displayable :)
you should a) use query_first
and then you have an array, so you have to use the right key :)

Chris M
06-11-2003, 05:50 PM
So you are saying:

$score = $DB_site->query("SELECT '$whichscore' FROM *tablename*_questions WHERE qid='$theqid'");
should be:
$score = $DB_site->query_first("SELECT '$whichscore' FROM *tablename*_questions WHERE qid='$theqid'");
As for the bit about array, would you mind going into more detail?:)

Satan

filburt1
06-11-2003, 06:02 PM
Yes. That resource thing isn't an error, it's just the handle of the query, cast to a string.

Chris M
06-11-2003, 06:28 PM
Ok:)

This 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 VARCHAR: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