UQM 2.0 - Predictions Extensions

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

Post Reply
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hmm, damn.

Try this:

Code: Select all

<?php
// subvertbeats_quiz.php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);

	if( !$auth->acl_get('a_') )
	{
		die('No access');
	}

	else
	{
		if( $_GET['mode'] == 'deactivate' )
		{
			$deactivate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
					WHERE quiz_id = $deactivate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $deactivate_id . ' has been deactivated');
		}

		if( $_GET['mode'] == 'activate' )
		{
			$activate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
					WHERE quiz_id = $activate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $activate_id . ' has been activated');
		}

		if( $_GET['mode'] == 'enter_answers' )
		{
			if( $_GET['a'] == 'submit' )
			{
				$question_id_hidden = $_POST['questions'];
				$question_id_set = explode(',', $question_id_hidden);
				$question_id_set_count = sizeof($question_id_set) - 1;

				$users = array();
				$users_information = array();

				for($i = 0; $i < $question_id_set_count; $i++ )
				{
					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i];
					$result = $db->sql_query($sql);
					while( $row = $db->sql_fetchrow($result) )
					{
						$users[$i] = $row['quiz_player'];

						$user_sql = 'SELECT username FROM ' . USERS_TABLE . '
									 WHERE user_id = ' . $row['quiz_player'];
						$user_result = $db->sql_query($user_sql);
						$user_name_fetch = $db->sql_fetchfield('username');
						$db->sql_freeresult($user_result);

						$users[$i]['name'] = $user_name_fetch;

						$is_correct = 0;
						$is_incorrect = 0;

						if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
			
							$users_information[$user_name_fetch][] = 'Question ' . $question_id_set[$i] . ' correct';
						$is_correct++;
						}

						else
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';
							$users_information[$user_name_fetch][] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';

						$is_incorrect++;
						}

						// stats
						$statistical_overview_setup[] = array(
							'quiz_id'			=> (int) $row['quiz_id'],
  							'quiz_correct'		=> (int) $is_correct,
  							'quiz_incorrect'	=> (int) $is_incorrect,
 							'user_id'			=> (int) $row['quiz_player'],
 							'quiz_time'			=> (int) 0,
						);
					}
				}

				for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
				{
					echo 'NAME: ' . $users[$j]['name'] . '<br />';
				}

				print_r($users_information);

				// Enter stats
				$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $statistical_overview_setup);

				die();
			}

			$quiz_id = (int) $_GET['id'];
			$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
					WHERE quiz_related_id = ' . $quiz_id;
			$result = $db->sql_query($sql);
			echo '<form action="subvertbeats_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
			$question_id_hidden = '';
			while( $row = $db->sql_fetchrow($result) )
			{	
				$question_id_hidden .= $row['quiz_question_id'] . ',';
				echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
				// echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
				echo 'Correct answer:';

				$ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
						WHERE quiz_question_id = ' . $row['quiz_question_id'];
				$ans_res = $db->sql_query($ans);
				while( $ans_row = $db->sql_fetchrow($ans_res) )
				{
					echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . '&nbsp;&nbsp;&nbsp;';
				} 

				echo '<br /><br />';
			}
			echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
			echo '<input type="submit" value="Submit" name="submit" />';
			echo '</form>';

			die(); // new
		}

		else
		{
			echo 'Mode types:<br />
				<strong>subvertbeats_quiz.php?mode=deactivate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=activate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=enter_answers&id=XXX</strong>';
			die();
		}
	}
?>
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Ok, no errors, and the following output (as before):
User subvertbeats answered question 1 INCORRECTLY. They entered the answer Fighter A.
User subvertbeats answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Lyoto answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Kamara666 answered question 1 CORRECTLY
User Nezerous answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Dent answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Dragonfoxy answered question 1 INCORRECTLY. They entered the answer Fighter A.
User subvertbeats answered question 2 INCORRECTLY. They entered the answer Fighter C.
User subvertbeats answered question 2 INCORRECTLY. They entered the answer Fighter C.
User Lyoto answered question 2 INCORRECTLY. They entered the answer Draw.
User Kamara666 answered question 2 CORRECTLY
User Nezerous answered question 2 INCORRECTLY. They entered the answer Fighter C.
User Dent answered question 2 CORRECTLY
User Dragonfoxy answered question 2 INCORRECTLY. They entered the answer Fighter C.
User subvertbeats answered question 3 INCORRECTLY. They entered the answer Fighter F.
User subvertbeats answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Lyoto answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Kamara666 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Nezerous answered question 3 INCORRECTLY. They entered the answer Fighter E.
User Dent answered question 3 CORRECTLY
User Dragonfoxy answered question 3 INCORRECTLY. They entered the answer Fighter E.
NAME: D
NAME: D
NAME: D
Array ( [subvertbeats] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 1 incorrect (Fighter A) [2] => Question 2 incorrect (Fighter C) [3] => Question 2 incorrect (Fighter C) [4] => Question 3 incorrect (Fighter F) [5] => Question 3 incorrect (Fighter F) ) [Lyoto] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 incorrect (Draw) [2] => Question 3 incorrect (Fighter F) ) [Kamara666] => Array ( [0] => Question 1 correct [1] => Question 2 correct [2] => Question 3 incorrect (Fighter F) ) [Nezerous] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 incorrect (Fighter C) [2] => Question 3 incorrect (Fighter E) ) [Dent] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 correct [2] => Question 3 correct ) [Dragonfoxy] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 incorrect (Fighter C) [2] => Question 3 incorrect (Fighter E) ) )
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Hmm, it means the database query for statistics worked but I just thought about it. It won't be recording the stats correctly. I think the only way we can do this correctly is to continue down the path of having it display by users (and then running the statistics for each user within each loop).

Essentially, we need to get the Array ( [subvertbeats] => Array ( [... working correctly.
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Try this and let me know what happens :)

Code: Select all

<?php
// subvertbeats_quiz.php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);

	if( !$auth->acl_get('a_') )
	{
		die('No access');
	}

	else
	{
		if( $_GET['mode'] == 'deactivate' )
		{
			$deactivate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
					WHERE quiz_id = $deactivate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $deactivate_id . ' has been deactivated');
		}

		if( $_GET['mode'] == 'activate' )
		{
			$activate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
					WHERE quiz_id = $activate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $activate_id . ' has been activated');
		}

		if( $_GET['mode'] == 'enter_answers' )
		{
			if( $_GET['a'] == 'submit' )
			{
				$question_id_hidden = $_POST['questions'];
				$question_id_set = explode(',', $question_id_hidden);
				$question_id_set_count = sizeof($question_id_set) - 1;

				$users = array();
				$users_information = array();
				$users_names = array();

				for($i = 0; $i < $question_id_set_count; $i++ )
				{
					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i];
					$result = $db->sql_query($sql);
					while( $row = $db->sql_fetchrow($result) )
					{
						$users[$i] = $row['quiz_player'];

						$user_sql = 'SELECT username FROM ' . USERS_TABLE . '
									 WHERE user_id = ' . $row['quiz_player'];
						$user_result = $db->sql_query($user_sql);
						$user_name_fetch = $db->sql_fetchfield('username');
						$db->sql_freeresult($user_result);

						$users_names[$row['quiz_player']] = $user_name_fetch;

						$is_correct = 0;
						$is_incorrect = 0;

						if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
			
							$users_information[$row['quiz_player']]['quiz_correct']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' correct';
						}

						else
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';

							$users_information[$row['quiz_player']]['quiz_incorrect']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
						}
					}
				}

				for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
				{
					echo 'Username: ' . $users_names[$users[$j]] . '<br />';
					echo '-- Correct: ' .  $users_information[$users[$j]]['quiz_correct'] . '<br />';
					echo '-- Incorrect: ' .  $users_information[$users[$j]]['quiz_incorrect'] . '<br />';
					echo '-- Quiz ID: ' .  $users_information[$users[$j]]['quiz_id'] . '<br />';
				}

				print_r($users_information);

				die();
			}

			$quiz_id = (int) $_GET['id'];
			$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
					WHERE quiz_related_id = ' . $quiz_id;
			$result = $db->sql_query($sql);
			echo '<form action="subvertbeats_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
			$question_id_hidden = '';
			while( $row = $db->sql_fetchrow($result) )
			{	
				$question_id_hidden .= $row['quiz_question_id'] . ',';
				echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
				// echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
				echo 'Correct answer:';

				$ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
						WHERE quiz_question_id = ' . $row['quiz_question_id'];
				$ans_res = $db->sql_query($ans);
				while( $ans_row = $db->sql_fetchrow($ans_res) )
				{
					echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . '&nbsp;&nbsp;&nbsp;';
				} 

				echo '<br /><br />';
			}
			echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
			echo '<input type="submit" value="Submit" name="submit" />';
			echo '</form>';

			die(); // new
		}

		else
		{
			echo 'Mode types:<br />
				<strong>subvertbeats_quiz.php?mode=deactivate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=activate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=enter_answers&id=XXX</strong>';
			die();
		}
	}
?>
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Hmm ok.....

The most important thing is (on a per quiz basis) being able to see a sorted list of users, with the following information for each user:

Correct Answers
Incorrect answers

And the list should be sorted in ascending order on the number of incorrect answers.

Anything else is not really so important.

Just about to try the new code above
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

output:
User subvertbeats answered question 1 INCORRECTLY. They entered the answer Fighter A.
User subvertbeats answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Lyoto answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Kamara666 answered question 1 CORRECTLY
User Nezerous answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Dent answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Dragonfoxy answered question 1 INCORRECTLY. They entered the answer Fighter A.
User subvertbeats answered question 2 INCORRECTLY. They entered the answer Fighter C.
User subvertbeats answered question 2 INCORRECTLY. They entered the answer Fighter C.
User Lyoto answered question 2 INCORRECTLY. They entered the answer Draw.
User Kamara666 answered question 2 CORRECTLY
User Nezerous answered question 2 INCORRECTLY. They entered the answer Fighter C.
User Dent answered question 2 CORRECTLY
User Dragonfoxy answered question 2 INCORRECTLY. They entered the answer Fighter C.
User subvertbeats answered question 3 INCORRECTLY. They entered the answer Fighter F.
User subvertbeats answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Lyoto answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Kamara666 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Nezerous answered question 3 INCORRECTLY. They entered the answer Fighter E.
User Dent answered question 3 CORRECTLY
User Dragonfoxy answered question 3 INCORRECTLY. They entered the answer Fighter E.
Username: Dragonfoxy
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Username: Dragonfoxy
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Username: Dragonfoxy
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Array ( [377] => Array ( [quiz_incorrect] => 6 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) ) [55] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) ) [88] => Array ( [quiz_correct] => 2 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) [quiz_incorrect] => 1 ) [945] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter E) ) [2] => Array ( [quiz_incorrect] => 1 [quiz_id] => 1 [info] => Question 3 correct [quiz_correct] => 2 ) [967] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter E) ) )
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

FIND

Code: Select all

				print_r($users_information);
BEFORE ADD:

Code: Select all

				print_r($users);
				print_r($users_names);
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Output seems to be the same
User subvertbeats answered question 1 INCORRECTLY. They entered the answer Fighter A.
User subvertbeats answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Lyoto answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Kamara666 answered question 1 CORRECTLY
User Nezerous answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Dent answered question 1 INCORRECTLY. They entered the answer Fighter A.
User Dragonfoxy answered question 1 INCORRECTLY. They entered the answer Fighter A.
User subvertbeats answered question 2 INCORRECTLY. They entered the answer Fighter C.
User subvertbeats answered question 2 INCORRECTLY. They entered the answer Fighter C.
User Lyoto answered question 2 INCORRECTLY. They entered the answer Draw.
User Kamara666 answered question 2 CORRECTLY
User Nezerous answered question 2 INCORRECTLY. They entered the answer Fighter C.
User Dent answered question 2 CORRECTLY
User Dragonfoxy answered question 2 INCORRECTLY. They entered the answer Fighter C.
User subvertbeats answered question 3 INCORRECTLY. They entered the answer Fighter F.
User subvertbeats answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Lyoto answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Kamara666 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User Nezerous answered question 3 INCORRECTLY. They entered the answer Fighter E.
User Dent answered question 3 CORRECTLY
User Dragonfoxy answered question 3 INCORRECTLY. They entered the answer Fighter E.
Username: Dragonfoxy
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Username: Dragonfoxy
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Username: Dragonfoxy
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Array ( [0] => 967 [1] => 967 [2] => 967 ) Array ( [377] => subvertbeats [55] => Lyoto [88] => Kamara666 [945] => Nezerous [2] => Dent [967] => Dragonfoxy ) Array ( [377] => Array ( [quiz_incorrect] => 6 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) ) [55] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) ) [88] => Array ( [quiz_correct] => 2 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) [quiz_incorrect] => 1 ) [945] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter E) ) [2] => Array ( [quiz_incorrect] => 1 [quiz_id] => 1 [info] => Question 3 correct [quiz_correct] => 2 ) [967] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter E) ) )
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Not quite, there is a little bit here: Array ( [0] => 967 [1] => 967 [2] => 967 ) Array ( [377] => subvertbeats [55] => Lyoto [88] => Kamara666 [945] => Nezerous [2] => Dent [967] => Dragonfoxy )

That is different, and quite helpful. Sorry this bit is causing some problems, I didn't expect it would take this long.
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Please battye, you really should not be apologizing - Im extremely grateful for you going out of your way to help.
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

:)

Try this:

Code: Select all

<?php
// subvertbeats_quiz.php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);

	if( !$auth->acl_get('a_') )
	{
		die('No access');
	}

	else
	{
		if( $_GET['mode'] == 'deactivate' )
		{
			$deactivate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
					WHERE quiz_id = $deactivate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $deactivate_id . ' has been deactivated');
		}

		if( $_GET['mode'] == 'activate' )
		{
			$activate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
					WHERE quiz_id = $activate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $activate_id . ' has been activated');
		}

		if( $_GET['mode'] == 'enter_answers' )
		{
			if( $_GET['a'] == 'submit' )
			{
				$question_id_hidden = $_POST['questions'];
				$question_id_set = explode(',', $question_id_hidden);
				$question_id_set_count = sizeof($question_id_set) - 1;

				$users = array();
				$users_information = array();
				$users_names = array();

				for($i = 0; $i < $question_id_set_count; $i++ )
				{
					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i];
					$result = $db->sql_query($sql);
					while( $row = $db->sql_fetchrow($result) )
					{
						$users[$i] = $row['quiz_player'];

						$user_sql = 'SELECT username FROM ' . USERS_TABLE . '
									 WHERE user_id = ' . $row['quiz_player'];
						$user_result = $db->sql_query($user_sql);
						$user_name_fetch = $db->sql_fetchfield('username');
						$db->sql_freeresult($user_result);

						$users_names[$row['quiz_player']] = $user_name_fetch;

						$is_correct = 0;
						$is_incorrect = 0;

						if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
			
							$users_information[$row['quiz_player']]['quiz_correct']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' correct';
						}

						else
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';

							$users_information[$row['quiz_player']]['quiz_incorrect']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
						}
					}
				}

				/* for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
				{
					echo 'Username: ' . $users_names[$users[$j]] . '<br />';
					echo '-- Correct: ' .  $users_information[$users[$j]]['quiz_correct'] . '<br />';
					echo '-- Incorrect: ' .  $users_information[$users[$j]]['quiz_incorrect'] . '<br />';
					echo '-- Quiz ID: ' .  $users_information[$users[$j]]['quiz_id'] . '<br />';
				} */

				foreach($users_names as $key => $val)
				{
					// $key is the user_id, $val is the username
					echo 'Info for ' . $val . ';<br />';
					echo '-- Correct: ' .  $users_information[$key]['quiz_correct'] . '<br />';
					echo '-- Incorrect: ' .  $users_information[$key]['quiz_incorrect'] . '<br />';
					echo '-- Quiz ID: ' .  $users_information[$key]['quiz_id'] . '<br />';
				}

				print_r($users_information);

				die();
			}

			$quiz_id = (int) $_GET['id'];
			$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
					WHERE quiz_related_id = ' . $quiz_id;
			$result = $db->sql_query($sql);
			echo '<form action="subvertbeats_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
			$question_id_hidden = '';
			while( $row = $db->sql_fetchrow($result) )
			{	
				$question_id_hidden .= $row['quiz_question_id'] . ',';
				echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
				// echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
				echo 'Correct answer:';

				$ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
						WHERE quiz_question_id = ' . $row['quiz_question_id'];
				$ans_res = $db->sql_query($ans);
				while( $ans_row = $db->sql_fetchrow($ans_res) )
				{
					echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . '&nbsp;&nbsp;&nbsp;';
				} 

				echo '<br /><br />';
			}
			echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
			echo '<input type="submit" value="Submit" name="submit" />';
			echo '</form>';

			die(); // new
		}

		else
		{
			echo 'Mode types:<br />
				<strong>subvertbeats_quiz.php?mode=deactivate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=activate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=enter_answers&id=XXX</strong>';
			die();
		}
	}
?>
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Getting there!

after the initial output we get:
Info for subvertbeats;
-- Correct:
-- Incorrect: 6
-- Quiz ID: 1
Info for Lyoto;
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Info for Kamara666;
-- Correct: 2
-- Incorrect: 1
-- Quiz ID: 1
Info for Nezerous;
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Info for Dent;
-- Correct: 2
-- Incorrect: 1
-- Quiz ID: 1
Info for Dragonfoxy;
-- Correct:
-- Incorrect: 3
-- Quiz ID: 1
Array ( [377] => Array ( [quiz_incorrect] => 6 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) ) [55] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) ) [88] => Array ( [quiz_correct] => 2 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter F) [quiz_incorrect] => 1 ) [945] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter E) ) [2] => Array ( [quiz_incorrect] => 1 [quiz_id] => 1 [info] => Question 3 correct [quiz_correct] => 2 ) [967] => Array ( [quiz_incorrect] => 3 [quiz_id] => 1 [info] => Question 3 incorrect (Fighter E) ) )
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Okay, this should fix the problem of some users having a blank field for "correct". It should be 0.

Is the "Info for" areas matching the initial output? ie. the number of correct/incorrect answers is right?

Code: Select all

<?php
// subvertbeats_quiz.php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);

	if( !$auth->acl_get('a_') )
	{
		die('No access');
	}

	else
	{
		if( $_GET['mode'] == 'deactivate' )
		{
			$deactivate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
					WHERE quiz_id = $deactivate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $deactivate_id . ' has been deactivated');
		}

		if( $_GET['mode'] == 'activate' )
		{
			$activate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
					WHERE quiz_id = $activate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $activate_id . ' has been activated');
		}

		if( $_GET['mode'] == 'enter_answers' )
		{
			if( $_GET['a'] == 'submit' )
			{
				$question_id_hidden = $_POST['questions'];
				$question_id_set = explode(',', $question_id_hidden);
				$question_id_set_count = sizeof($question_id_set) - 1;

				$users = array();
				$users_information = array();
				$users_names = array();

				for($i = 0; $i < $question_id_set_count; $i++ )
				{
					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i];
					$result = $db->sql_query($sql);
					while( $row = $db->sql_fetchrow($result) )
					{
						$users[$i] = $row['quiz_player'];

						$user_sql = 'SELECT username FROM ' . USERS_TABLE . '
									 WHERE user_id = ' . $row['quiz_player'];
						$user_result = $db->sql_query($user_sql);
						$user_name_fetch = $db->sql_fetchfield('username');
						$db->sql_freeresult($user_result);

						$users_names[$row['quiz_player']] = $user_name_fetch;

						$is_correct = 0;
						$is_incorrect = 0;

						if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
			
							$users_information[$row['quiz_player']]['quiz_correct']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' correct';
						}

						else
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';

							$users_information[$row['quiz_player']]['quiz_incorrect']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
						}
					}
				}

				/* for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
				{
					echo 'Username: ' . $users_names[$users[$j]] . '<br />';
					echo '-- Correct: ' .  $users_information[$users[$j]]['quiz_correct'] . '<br />';
					echo '-- Incorrect: ' .  $users_information[$users[$j]]['quiz_incorrect'] . '<br />';
					echo '-- Quiz ID: ' .  $users_information[$users[$j]]['quiz_id'] . '<br />';
				} */

				foreach($users_names as $key => $val)
				{
					// $key is the user_id, $val is the username
					$correct_answers = ($users_information[$key]['quiz_correct']) ? $users_information[$key]['quiz_correct'] : 0;
					$incorrect_answers = ($users_information[$key]['quiz_incorrect']) ? $users_information[$key]['quiz_incorrect'] : 0;
					$quiz_id_key = $users_information[$key]['quiz_id'];

					echo 'Info for ' . $val . ';<br />';
					echo '-- Correct: ' .  $correct_answers . '<br />';
					echo '-- Incorrect: ' .  $incorrect_answers . '<br />';
					echo '-- Quiz ID: ' . $quiz_id_key . '<br />';
				}

				die();
			}

			$quiz_id = (int) $_GET['id'];
			$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
					WHERE quiz_related_id = ' . $quiz_id;
			$result = $db->sql_query($sql);
			echo '<form action="subvertbeats_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
			$question_id_hidden = '';
			while( $row = $db->sql_fetchrow($result) )
			{	
				$question_id_hidden .= $row['quiz_question_id'] . ',';
				echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
				// echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
				echo 'Correct answer:';

				$ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
						WHERE quiz_question_id = ' . $row['quiz_question_id'];
				$ans_res = $db->sql_query($ans);
				while( $ans_row = $db->sql_fetchrow($ans_res) )
				{
					echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . '&nbsp;&nbsp;&nbsp;';
				} 

				echo '<br /><br />';
			}
			echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
			echo '<input type="submit" value="Submit" name="submit" />';
			echo '</form>';

			die(); // new
		}

		else
		{
			echo 'Mode types:<br />
				<strong>subvertbeats_quiz.php?mode=deactivate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=activate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=enter_answers&id=XXX</strong>';
			die();
		}
	}
?>
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

New output
Info for subvertbeats;
-- Correct: 0
-- Incorrect: 6
-- Quiz ID: 1
Info for Lyoto;
-- Correct: 0
-- Incorrect: 3
-- Quiz ID: 1
Info for Kamara666;
-- Correct: 2
-- Incorrect: 1
-- Quiz ID: 1
Info for Nezerous;
-- Correct: 0
-- Incorrect: 3
-- Quiz ID: 1
Info for Dent;
-- Correct: 2
-- Incorrect: 1
-- Quiz ID: 1
Info for Dragonfoxy;
-- Correct: 0
-- Incorrect: 3
-- Quiz ID: 1
And yes, the data here matches the actual submitted data x-ref'd with the correct answers.

Of course it looks a little off due to my double entires in this particular quiz
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Were you able to replicate that double-entry problem here at CMX?
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Post Reply