marcus88 Posted March 2, 2003 Share Posted March 2, 2003 Hello I am currently designing a web site for an on-line test with php and Mysql using apache server. I have to randomly pick questions from Mysql database via the server too displays on the main viewing screen. I would be grateful if you could point me in the right direction. Hope this makes sense because its starting to get me confuse I have just designed the main screen which generates the password with username. Thanks :? Quote Link to comment Share on other sites More sharing options...
NL_Johan_UK Posted March 3, 2003 Share Posted March 3, 2003 I assume you have all questions stored in tables already. For a random question select, do this query first: SELECT MIN(id), MAX(id) FROM your_question_table I assume the ID is autoincremental, with no deleted records. Then you have the minimum and maximum ID\'s. Use them for this: srand((double)microtime()*1000000); $random_number = rand(0,100); where 0 is your minimum and 100 your maximum... Now select your random question: SELECT question FROM your_question_table WHERE id = \'$random_number\' There are many sources online on random strings and numbers, just search in google... Quote Link to comment Share on other sites More sharing options...
marcus88 Posted March 3, 2003 Author Share Posted March 3, 2003 Thanks I’m having a problem with my database I’m not to sure how many fields to put I have a main screen for the users to view and there will have a choice of four questions to chose from with one being the right answer. Will I have to create four separate fields with 4 wrong answers and one right and how will it no to generate the correct answer? That’s the problem I’m having its driving my mad. :oops: Quote Link to comment Share on other sites More sharing options...
NL_Johan_UK Posted March 3, 2003 Share Posted March 3, 2003 I think you mixed up some words like qestion and answer but let me try. You only need to store the right answer. I take it you use a drop down select option list , so all answers have a value. To see whether it was the right answer do this: $query = "SELECT COUNT(*) FROM your_table WHERE correct_answer_field = $visitors_answer"; $result = mysql_query($query); if(mysql_num_rows($result) < 1) { echo\'they were wrong\'; } else { echo\'they guessed it right\'; } Quote Link to comment 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.