Page 1 of 1

How to create this app (fetching questions & answers MYSQL)

Posted: Wed May 25, 2011 6:34 pm
by KyZu
I've just learned the basics of MySQL last night and made a simple app (where a user enters a song name, song title, and rating (out of 5) and it displays the list of songs with the highest rated songs first).

So I decided I wanted to make something similar yet slightly more complicated and I'm not sure if I'm on the right track. Basically it's a "flash card" game where:

- The user gets to input their own questions and answers into a simple form, which would then go into an MySQL table with 2 columns, questions and answers
- A new page where the user see's random question, must input an answer, if the answer matches goes to next question otherwise gives error

Now I'm confused as to how to go about making this. I was thinking of making some session variables and then do something along the lines of

Code: Select all

	 
$display_query = "SELECT * FROM questions";
$display = mysqli_query($connection, $display_query);
	      
	      while ($row = mysqli_fetch_array($display)) {
		$_SESSION['question'] = $row[0];
	      }
and then make some PHP that might do something like this:

Code: Select all

            if ($_SESSION['answer'] != $row[1]) {
           echo "error, try again"
} else {
           // I would write something here to grab the next question
}

So am I just completely off the wall with this, how would I make such an app? How would I make it, for example, fetch new questions?

Re: How to create this app (fetching questions & answers MYS

Posted: Thu Jun 02, 2011 10:23 am
by Jade
You can either use sessions or a database to store the last question they answered. From there you can query the database to pull in the next question depending on which one they are currently on. Or you can randomly select a question to ask them.

Re: How to create this app (fetching questions & answers MYS

Posted: Mon Jun 06, 2011 2:56 pm
by thinsoldier
How long are the answers? If they're all one word answers, fine. But if not some poor spellers might get frustrated. Don't forget to trim() their submitted answer before comparing it to the real answer.