Jump to content

Archived

This topic is now archived and is closed to further replies.

realjumper

Limiting loops

Recommended Posts

Hi,

My query selects from a table of say 25 records. It orders by rand() with a limit of 16. Here is my standard loop

[code]
while ($row1 = mysql_fetch_assoc($result1)) {
              $id[] = $row1['id'];
              $sentence[] = $row1['sentence'];
              $start[] = $row1['start'];
              $end[] = $row1['end'];
}
[/code]

The idea is that a sentence (in Japanese Kanji) is displayed, and the sentence is actually a question for which there is only one answer. The user gets to type the answer into a text field and submits the form. The database is queried to see whether the question is right or wrong. A running total of right answers and wrong answers is displayed, as well as the percentage of correct answers from the number of attempts.

In my temporary table, the question is recorded as is the correct answer. Also recorded is the users answer, no matter whether their answer is right or wrong.

Currently, the user answers the question, the correct answer is displayed and their score incremented. Then, after clicking the 'Next' button, another question is displayed and so on. All of the above takes place in the same php page.....as it needs to (I think) to keep the temporary table alive.

What I want to do is to limit the number of attempts to (say) 20....doesn't matter that the same question may be asked more than once. After the 20th attempt, I wish to display the 20 questions with their correct answers as well as the users answer. Then they may attempt the wrong answered questions again if they want to. I can see how to do most of that. What I can't see is how to end the 'test' at 20, so that the option of 'Next' no longer appears. Instead the user will see the total results of his test which he can choose to resit the wrong questions etc.

So, my question is how do I end the test at (for example) the 20th attempt.....that is the 20th time the loop has executed?

Thanks for any help

Neil

Share this post


Link to post
Share on other sites
I think I have the answer to my own question....I don't need to worry about the loop because if I add the right and wrong answers I know the total number of attempts....and this I am already doing. So,
[code]
$total_attempts=$right+$wrong;

if ($total_attempts=='20')
{
do this stuff
}

else{
do somthing else
}
[/code]

Does that sound right?...it's been a long day!!

Neil

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.