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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KyZu
Forum Newbie
Posts: 17
Joined: Sun Apr 24, 2011 9:13 pm

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

Post 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?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

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

Post 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.
Last edited by Jade on Tue Jun 07, 2011 9:17 am, edited 1 time in total.
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

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

Post 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.
Warning: I have no idea what I'm talking about.
Post Reply