realjumper Posted March 21, 2006 Share Posted March 21, 2006 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 helpNeil Quote Link to comment https://forums.phpfreaks.com/topic/5384-limiting-loops/ Share on other sites More sharing options...
realjumper Posted March 21, 2006 Author Share Posted March 21, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5384-limiting-loops/#findComment-19211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.