Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2003, 03:35 PM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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), 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)

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
Reply With Quote
  #2  
Old 06-16-2003, 07:14 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please can anyone help?

I really need to get this finished...

Satan
Reply With Quote
  #3  
Old 06-16-2003, 07:40 AM
Cloudrunner's Avatar
Cloudrunner Cloudrunner is offline
 
Join Date: May 2003
Location: Butte, MT
Posts: 635
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 06-16-2003, 08:04 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 06-16-2003, 08:28 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default



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

Satan
Reply With Quote
  #6  
Old 06-16-2003, 08:29 AM
Cloudrunner's Avatar
Cloudrunner Cloudrunner is offline
 
Join Date: May 2003
Location: Butte, MT
Posts: 635
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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".
Reply With Quote
  #7  
Old 06-16-2003, 08:34 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Satan
Reply With Quote
  #8  
Old 06-16-2003, 08:40 AM
Cloudrunner's Avatar
Cloudrunner Cloudrunner is offline
 
Join Date: May 2003
Location: Butte, MT
Posts: 635
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

np...lemme know.
Reply With Quote
  #9  
Old 06-16-2003, 08:53 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 06-16-2003, 08:59 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06015 seconds
  • Memory Usage 2,283KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete