vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Need help finishing... (https://vborg.vbsupport.ru/showthread.php?t=54371)

Chris M 06-15-2003 02:35 PM

Need help finishing...
 
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):)

Code:

          $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 06:14 AM

Please can anyone help?

I really need to get this finished...

Satan

Cloudrunner 06-16-2003 06:40 AM

Quote:

Code:

          $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:

PHP Code:

$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:

PHP Code:

$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 07:04 AM

Aha thanks...

Yes $whichscore is a earlier defined variable, via this code:

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 07:28 AM

:(

Unfortunately the code still returns "gscore" , "hscore", "sscore" and "rscore":(

Satan

Cloudrunner 06-16-2003 07:29 AM

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".

Chris M 06-16-2003 07:34 AM

Hmm...I never thought of that - I shall try, thanks:D:)

Satan

Cloudrunner 06-16-2003 07:40 AM

np...lemme know.

Chris M 06-16-2003 07: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:

Code:

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 07: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


All times are GMT. The time now is 02:49 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02037 seconds
  • Memory Usage 1,763KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete