/    Sign up×
Community /Pin to ProfileBookmark

hello all, I am trying to the score but it is not coming up. Any help would be great

[code=php]
for($i = 0; $i < $_REQUEST[“answer”.$i]; $i++)
{

if($queryResult == $_REQUEST[“answer”.$i])
{
echo “<input type = “radio” name = “correct” id =

“correct” checked />”;
$totalScore += 20;
}
else
{
echo “<input type = “radio” name = “incorrect”

id = “incorrect” />”;
$totalScore += 0;
}

}
[/code]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 04.2005 — what's the value of $_REQUEST["answer".$i] ?
Copy linkTweet thisAlerts:
@harlemrisinauthorDec 04.2005 — it is supposed to get the answers from the database
Copy linkTweet thisAlerts:
@chazzyDec 04.2005 — right, but by using the request array, you are getting the answers from a form somewhere. and you're saying to do it as long as $i < $_REQUEST["answer".$i] which has no reason to be true, and you're changing the value each time.
Copy linkTweet thisAlerts:
@harlemrisinauthorDec 04.2005 — ok this is what i'm trying to do...i'm tryin to calculate the score, add the score to the database, figure out the average score, and display both the user's score and the average score to the browser. The scores wont calculate at all and the checked buttons for correct/incorrect will not fill saying wheither the answer is right/wrong. i have inclosed the entire code so you can see what I'm trying to do. and hopefully you can help me...thanks again

[upl-file uuid=67e19d5f-6c2d-42f5-8dfa-05b02bba139f size=3kB]um.txt[/upl-file]
Copy linkTweet thisAlerts:
@bathurst_guyDec 04.2005 — Ok i dont know how to fix the question you asked - i dont really understand what your doing and what the db contains etc, but heres something that i picked up from your code that needs fixing:
>= means greater than or equal to

<= means less than or equal to

so therefore

if(($totalScore >= 80) && ($totalScore <= 60)) {

if totalscore is greater than or equal to 80 and less than or equal to 60 ...

returns false no matter what the number, this applies for all of your expressions
Copy linkTweet thisAlerts:
@SpectreReturnsDec 05.2005 — for($i = 0; $i < $_REQUEST["answer".$i]; $i++)

Since $i isn't yet set, this is going to act oddly. You're currently telling it to:

set i = 0
if 0 &lt; answer0
continue
if 1 &lt; answer1
continue

As you can see, this makes no sense. You will want to put in a hidden form value to tell you how many answers there are, (or make each answer called answer[], and populate an array).
Copy linkTweet thisAlerts:
@harlemrisinauthorDec 05.2005 — o ok....thanks man
×

Success!

Help @harlemrisin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...