Results 1 to 2 of 2
Sep 10, 2009, 07:26 #1
- Join Date
- Aug 2009
- 0 Post(s)
- 0 Thread(s)
Getting interaction on multiple records of same array
I'm trying to build an application to quiz my children on math facts. I have stored math fact "families" in a MySQL table. My PHP code (in index.php) selects the pertinent records from the table and places them into an array such that $families contains a number of arrays which each include an id and three numbers. I will be resorting $families so that its elements are in a random order.
Now I want to send each set of numbers to a display page that will present the numbers to my children as a math problem which they can answer. I will save the results of their answers, along with the numbers in the problem, in another table.
The problem I have is determining the best method to present each set of problems to the children. I have a display.html.php page that will present the first set of numbers as a math problem, but once that question has been answered, I find a dilemma in being able to move back to my control script (index.php) and then sending the following sets of numbers to display.html.php, one set at a time.
I have the book, Build Your Own Database Driven Web Site Using PHP & MYSQL, and I have read through most of it several times, but I can't find a section relevant to what I'm trying to do. I would appreciate any help with how to overcome this dilemma.
Sep 10, 2009, 07:48 #2
You don't need to necessarily randomize the data in PHP (but you can...arrays are simple to shuffle in PHP), but your SELECT clause in mySQL can end with "ORDER BY RAND()" and it will shuffle them.
In order to fix your problem, you might want to consider using sessions. Basically, upon the first execution of a script you set two session variables. One that contains an array of your questions, and then another that contains an array of question ID's that they have already answered. So as they go through the questions and you process them, you update this array with the ID of the question they just answered. The script that renders the questions will just use these as a reference so you don't ask the same questions twice.
This is just ONE way of doing this...there's countless others...hope this helps..