Online Quiz

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
Strider64
php-forum Active User
php-forum Active User
Posts: 307
Joined: Sat Mar 23, 2013 8:24 am

Tue Apr 30, 2013 1:31 pm

Yes, it's possible to make a trivia/quiz game using php; however, it would be best to use JQuery(JavaScript) and maybe a little AJAX along with php.

Here's something I was goofing around in php a couple of months ago, I was trying to see if I could convert a game that I did in flash/php and make it strictly php. This is only one page:

Code: Select all

<?php require_once("includes/common.php"); ?>
<?php require("includes/DatabaseConnectionClass.php"); ?>
<?php require("includes/ReadTriviaDataClass.php"); ?>
<?php
    		
	$trivia_menu = array();
	$display_trivia_menu = array();
	
	$next = new ReadTriviaData;
	$trivia = new ReadTriviaData;
	$trivia_menu = $trivia->get_trivia_data();
	
	// Check to see if user has click on the menu	
	if (isset($_GET['answer']) && isset($_GET['show']) && isset($_GET['page']))
	{
	    $show = $_GET['show'];
	    $x = $_GET['page'];  // Get the current page / question 
	    $answer = $_GET['answer']; // Get user's response to the question
	    
	    $message = $trivia->game_controls($trivia_menu, $x, $answer);
	    $show = 0;
	} 
	else
	{ 
		$x = 0;
		$show = 1;
		$message = 'Please select your answer: ';
	}					
		
	if (isset($_GET['next']))
	{
	    $show = 1;
	    $x = $_GET['next'] + 1;	
	}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Pepster's Trivia Game Beta 1.0</title>
<link href="css/user_style.css" rel="stylesheet" type="text/css" >
</head>

<body>
	<section>
	  <!--/Displays the Question & Possible Answers-->
       <?php $trivia->trivia_menu($trivia_menu, $x, $show); ?>
       
       <div id = "next-style">       
       	<h5><?php echo $message ?></h5>
       	<p><?php echo $next->next_question($x); ?></p>	
       </div>
       
       <footer>
       </footer>
       
     </section>
</body>
</html>
A couple of things about it, first like I said I was just testing to see if is possible to do it solely php and just did this on my local server. If was going to put it on the internet I would sanitize my variables first and lastly I wouldn't don't it all in php for while php is good for pulling information from the server. JavaScript (even Flash) is better for the client side of things.

Post Reply