The Arcive of vBulletin Modifications Site. |
|
|
#1
|
||||
|
||||
|
Sounds silly, but anyway...
I have 4 fields in the user table, score1,score2,score3 and score4... These store the scores from each stage of a test I make the user's take... Anyway, I want to know how to add the contents of the fields together (also what field types I would need), so that the following will work: Code:
$total = $DB_site->query("SELECT score1,score2,score3,score4 FROM user WHERE userid='$bbuserinfo[userid]'");
$addingup = "ADDING UP BIT";
$totalscore = "THE RESULT";
if ($totalscore<=6) {
$group=='9';
}elseif ($totalscore>=7 AND $totalscore<=10) {
$group=='11';
}elseif ($totalscore>=11 AND $totalscore<=13) {
$group=='10';
}else{
$group=='8';
}
$usergroupname = $DB_site->query("SELECT * FROM usergroup WHERE usergroupid='$group'");
$DB_site->query("UPDATE user SET usergroupid='$group' WHERE userid='$bbuserinfo[userid]'");
![]() Edit: Extra Info - There are 4 questions, each with 4 possible answers, which are assigned a point value from 1 to 4, 4 being the highest and "best" answer, 1 being the lowest and "worst" answer (as such )Satan |
|
#2
|
||||
|
||||
|
why not fetch the scores by user id as you doing, but then have a bit of code like where the id matches the userid add the 4 scores together...
simple maths.. or am i missing something as usual lol or let me guess thast what u wana know try this : PHP Code:
|
|
#3
|
||||
|
||||
|
I'm not sure what you mean dave
![]() The script inserts the score from each stage into a seperate field... The script then needs to calculate the total score from those 4 fields, so that the user's usergroupid can be updated based on their score... Satan |
|
#4
|
||||
|
||||
|
Ok I have the add-up code (which I believe works), but for some reason the fields:
question1 question2 question3 question4 and score1 score2 score3 score4 are not being updated, and are blank ![]() Satan |
|
#5
|
|||
|
|||
|
I'm not sure I understand?
PHP Code:
|
|
#6
|
||||
|
||||
|
Thanks N9ne, but I have the adding up bit
![]() ![]() My problem now is that for some reason the database is not being given the values of the variables ![]() I'll figure it out or die trying ![]() Thanks for your help though ![]() ![]() Satan |
|
#7
|
|||
|
|||
|
So you want score1,score2,score3,score4 fields in the user table to be updated with the new scores?
PHP Code:
|
|
#8
|
|||
|
|||
|
Maybe I'm completely confused but:
[sql] SELECT score1 + score2 + score3 + score4 AS totalscore FROM user WHERE userid = userid; [/sql] |
|
#9
|
||||
|
||||
|
I told you how to do this earlier
. Have the main pagePHP Code:
PHP Code:
![]() - miSt |
|
#10
|
||||
|
||||
|
Hehe - The counting is no longer the problem...
I now have a problem with this code: Code:
// ############################### start update4 ###############################
if ($action=="update4") {
$qid = intval($question4[qid]);
$question4 = intval($question4[question]);
$ganswer = intval($question4[ganswer]);
$sanswer = intval($question4[sanswer]);
$hanswer = intval($question4[hanswer]);
$ranswer = intval($question4[ranswer]);
$answer = intval($answer);
$answer1 = intval($answer1);
$answer2 = intval($answer2);
$answer3 = intval($answer3);
$answer4 = intval($answer4);
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='$qid'");
if ($bbuserinfo['usergroupid']==2)
{
$DB_site->query("UPDATE user SET question4='$qid',score4='$score[$whichscore]' WHERE userid='$bbuserinfo[userid]'");
}
$total = $DB_site->query("SELECT score1,score2,score3,score4 FROM user WHERE userid='$bbuserinfo[userid]'");
while($r1 = mysql_fetch_array($total)){
$score1=$r1['score1'];
$score2=$r1['score2'];
$score3=$r1['score3'];
$score4=$r1['score4'];
$subtotal1 = $score1 + $score2 ;
$subtotal2 = $subtotal1 + $score3 ;
$finaltotal = $subtotal2 + $score4 ;
}
if ($finaltotal<=6) {
$group=='9';
}elseif ($finaltotal>=7 AND $finaltotal<=10) {
$group=='11';
}elseif ($finaltotal>=11 AND $finaltotal<=13) {
$group=='10';
}else{
$group=='8';
}
$usergroupname = $DB_site->query("SELECT * FROM usergroup WHERE usergroupid='$group'");
$DB_site->query("UPDATE user SET usergroupid='$group' WHERE userid='$bbuserinfo[userid]'");
$goto="index.php?s=$session[sessionhash]";
eval("standardredirect(\"".gettemplate("congrats_sorted")."\",\"$goto\");");
}
$question4 = the 4th question $ganswer = one of the answer options $sanswer = another answer option $hanswer = another answer option $ranswer = another answer option $answer = the answer they selected $answer1 = the 1st answer they could have chosen $answer2 = the 2nd answer they could have chosen $answer3 = the 3rd answer they could have chosen $answer4 = the 4th answer they could have chosen Thats pretty much all the explaination I can give - Here is the "question4" code: Code:
// ############################### start *tablename* ###############################
if ($action=="sort4") {
$getqs4 = $DB_site->query("SELECT * FROM *tablename*_questions ORDER BY RAND() LIMIT 1");
while ($question4=$DB_site->fetch_array($getqs4)) {
$answers4 = array($question4[ganswer],$question4[sanswer]);
$answers24 = array($question4[hanswer],$question4[ranswer]);
$nbvalue4 = 1;
$answerd4 = array_rand($answers4,$nbvalue4);
if ($answerd4=="$question4[ganswer]") {
$answer1 = "$question4[ganswer]";
$answer2 = "$question4[sanswer]";
}else{
$answer1 = "$question4[sanswer]";
$answer2 = "$question4[ganswer]";
}
$answert4 = array_rand($answers24,$nbvalue4);
if ($answert4=="$question4[hanswer]") {
$answer3 = "$question4[hanswer]";
$answer4 = "$question4[ranswer]";
}else{
$answer3 = "$question4[ranswer]";
$answer4 = "$question4[hanswer]";
}
eval("\$thequestions .= \"".gettemplate('*tablename*_questions4')."\";");
}
eval("dooutput(\"".gettemplate('*tablename*_q4')."\");");
}
![]() *tablename*_q4 Code:
<html>
<head>
<title>$bbtitle - *file name*</title>
$headinclude
</head>
$header
<body>
<!-- breadcrumb -->
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%"><br>
<normalfont><b><a href="index.php?s=$session[sessionhash]">$bbtitle</a>
> *File name* - Question 4</b></normalfont></td>
</tr>
</table>
<!-- /breadcrumb -->
<form action="*filename*.php" method="post">
<input type="hidden" name="s" value="$session[sessionhash]">
$thequestions
<br>
<table cellpadding="2" cellspacing="0" border="0" width="95%" align="center">
<tr>
<td align="center"><normalfont>
<input type="hidden" name="action" value="update4">
<input type="submit" class="bginput" name="Submit" value="Submit">
<input type="reset" class="bginput" name="Reset" value="Reset">
</normalfont></td>
</tr>
</table>
</form>
$footer
</body>
</html>
Code:
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#0A293E" width="95%" align="center"><tr><td> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr> <td bgcolor="#1D6AA0" colspan="2"><normalfont color="#EEEEFF"><b>The Question</b></normalfont></td> </tr> <tr> <td bgcolor="#1C5780"><normalfont><b>Quesion: $question4[question]?</b></normalfont></td> </tr> <tr> <td bgcolor="#13486D"><normalfont> <input type="radio" name="answer" value="answer1" checked>$answer1<br> <input type="radio" name="answer" value="answer2">$answer2<br> <input type="radio" name="answer" value="answer3">$answer3<br> <input type="radio" name="answer" value="answer4">$answer4<br> </normalfont></td> </tr> </table> </td></tr></table> ![]() *tablename* = The name of the table Problem I think it is: - "$qid" will not intval, so the"$whichscore" will not work ![]() Satan |
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|