# PHP/Mysql Based Trivia Game # Version 1.0 # README File # By Mike Calabrese # http://www.mikecalabrese.com/index.shtml # 01-10-2002 # This program is available for free on an AS-IS basis. I am not # responsible for consequential damages, loss of income or whatever # else that may happen as a result of the use of this program. This program is designed to ask and score 5 randomly selected trivia questions using the PHP scripting language and a Mysql database. The 13 files included are this README file, trivia.php, trivia.gif, trivia_question1.php, trivia_answer1.php, trivia_question2.php, trivia_answer2.php, trivia_question3.php, trivia_answer3.php, trivia_question4.php, trivia_answer4.php, trivia_question5.php, and trivia_answer5.php. PLEASE NOTE- You must have PHP4.0.6 or newer AND MySQL 3.23 or newer installed and running on your web server in order for these files to work. As far as particular questions about Mysql or PHP are concerned I would recommend 2 good books on these subjects: MySQL by Paul DuBois and PHP and MySQL Web Development by Luke Welling and Laura Thomson The way the application works is that the user is presented with 5 randomly selected questions via PHP scripts and a Mysql database. The user is presented their score and even their name is carried forward throughout the application via PHP. The following configuration changes need to be made in order to successfully run this program: 1) Within your Mysql database create a table called trivia with the following attributes: +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | question_number | mediumint(4) | | | 0 | | | question | varchar(255) | | | | | | answer1 | varchar(50) | | | | | | answer2 | varchar(50) | | | | | | answer3 | varchar(50) | | | | | | answer4 | varchar(50) | | | | | | answer5 | varchar(50) | | | | | | correct_answer | varchar(50) | | | | | +-----------------+--------------+------+-----+---------+-------+ Now the job of inserting the questions will fall upon you. The program is set up to utilize 1 or more groups of 5 questions (You configure that parameter in 3) below). The only restrictions are to be sure that the question number is a whole number and that the question numbers are con- current. Also, make sure that your correct answer is exactly the same as one of the possible answers as the program compares them in order to score the user. Here is an example of a sample question: 1 In what year did Honda introduce the Accord? a) 1975 b) 1976 c) 1980 d) 1985 e) None of the above b) 1976 (B is the correct answer) If you insert the questions in this format, you should have no problems. 2) If you downloaded the tarred and zipped version of the trivia .php files, simply upload them to where your html documents reside, unzip and untar the files. The result will be the trivia directory with all of the files that you need within it. On some servers you may need to chgroup these files to reflect the proper ownership of them. also, on some servers you may need to change the extension of the .php files to .php4 or .phtml If you got the necessary files via email create a directory on your web server where your html documents reside called trivia. Chmod that directory to 755. FTP the 12 files for this program to that directory. Also, be sure to save the image trivia.gif and then upload it as a binary file to that same trivia directory. This is the animated gif that provides the countdown mechanism. Be sure to chmod all files within the trivia directory to 755. On some servers you may need to change the extension of the .php files to .php4 or .phtml . 3) Now that you have your database set up and your files uploaded, it's time to configure the .php files in your trivia directory. trivia_question1.php- Line 24, This is the array the gets "shuffled" and the first element is read in as the starting point for the questions. If you only plan to have 5 questions, only the number 1 should be in the array. If you plan to have 10 questions, the numbers 1 and 6 should be in the array. If you plan to have 15 questions, the numbers 1, 6 and 11 should be in the array, etc, etc. In other words, make sure that a number that is the last number in the array + 5 should be in the array for every 5 questions. Line 30, if your Mysql database is on the same machine as your web server, then change "yourhostname" to "localhost". If it is on a different machine, change "yourhostname" to the name of that machine. "yourlogin" should be your login to your Mysql database, "yourpassword" should be your login password to your Mysql database. Line 32, replace "yourdatabase" with the name of your Mysql database. trivia_question2.php, trivia_question3.php, trivia_question4.php and trivia_question5.php- Make the same changes to "yourhostname", "yourlogin", "yourpassword" and "yourdatabase" as you did for trivia_question1.php above. If your database is set up properly, your questions and answers are inserted correctly and your .php files are installed and configured properly, then your trivia game should work with no problems.