Click to See Complete Forum and Search --> : for loop issue


harlemrisin
12-03-2005, 09:20 PM
hello all, I am trying to the score but it is not coming up. Any help would be great


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;
}

}

chazzy
12-03-2005, 09:57 PM
what's the value of $_REQUEST["answer".$i] ?

harlemrisin
12-03-2005, 10:14 PM
it is supposed to get the answers from the database

chazzy
12-03-2005, 11:03 PM
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.

harlemrisin
12-04-2005, 02:22 AM
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

bathurst_guy
12-04-2005, 03:38 AM
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

harlemrisin
12-04-2005, 12:09 PM
ok ty

SpectreReturns
12-04-2005, 09:17 PM
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 < answer0
continue
if 1 < 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).

harlemrisin
12-05-2005, 01:48 AM
o ok....thanks man