Before the headers warning, this is output:
Which looks correct to me.12
4
12 questions in the set, first question in the set with id 4
Moderator: CricketMX Forum Moderators
Which looks correct to me.12
4
Code: Select all
for($i = 0; $i < $question_id_set_count; $i++ )
{
Code: Select all
echo 'I: ' . $i . '<br />';
echo 'RES: ' . $question_id_set[$i] . '<br /><br />';
12
4I: 0
RES: 4
I: 1
RES: 5
I: 2
RES: 6
I: 3
RES: 7
I: 4
RES: 8
I: 5
RES: 9
I: 6
RES: 10
I: 7
RES: 11
I: 8
RES: 12
I: 9
RES: 13
I: 10
RES: 14
I: 11
RES:
Code: Select all
$question_id_set_count = sizeof($question_id_set);
Code: Select all
$question_id_set_count = sizeof($question_id_set) - 1;
User 377 answered question 1 CORRECTLYUser 377 answered question 1 CORRECTLYUser 55 answered question 1 CORRECTLYUser 88 answered question 1 INCORRECTLY. They entered the answer Fighter B.User 945 answered question 1 CORRECTLYUser 2 answered question 1 CORRECTLYUser 967 answered question 1 CORRECTLYUser 377 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 377 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 55 answered question 2 INCORRECTLY. They entered the answer Draw.User 88 answered question 2 CORRECTLYUser 945 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 2 answered question 2 CORRECTLYUser 967 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 377 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 377 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 55 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 88 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 945 answered question 3 INCORRECTLY. They entered the answer Fighter E.User 2 answered question 3 CORRECTLYUser 967 answered question 3 INCORRECTLY. They entered the answer Fighter E.
Code: Select all
echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
Code: Select all
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'] . ' ';
}
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'];
if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
{
echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY';
$users_information[$row['quiz_player']][] = 'Question ' . $question_id_set[$i] . ' correct';
}
else
{
echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.';
$users_information[$row['quiz_player']][] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
}
}
}
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'] . ' ';
}
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();
}
}
?>
subvertbeats wrote:Ok, now we're moving!
I made a simple 3 question quiz yesterday for a boxing event, and had a few forum mods do some dummy answers for testing.
So now we get:
User 377 answered question 1 CORRECTLYUser 377 answered question 1 CORRECTLYUser 55 answered question 1 CORRECTLYUser 88 answered question 1 INCORRECTLY. They entered the answer Fighter B.User 945 answered question 1 CORRECTLYUser 2 answered question 1 CORRECTLYUser 967 answered question 1 CORRECTLYUser 377 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 377 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 55 answered question 2 INCORRECTLY. They entered the answer Draw.User 88 answered question 2 CORRECTLYUser 945 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 2 answered question 2 CORRECTLYUser 967 answered question 2 INCORRECTLY. They entered the answer Fighter C.User 377 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 377 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 55 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 88 answered question 3 INCORRECTLY. They entered the answer Fighter F.User 945 answered question 3 INCORRECTLY. They entered the answer Fighter E.User 2 answered question 3 CORRECTLYUser 967 answered question 3 INCORRECTLY. They entered the answer Fighter E.
Code: Select all
echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY';
Code: Select all
echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
Code: Select all
echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.';
Code: Select all
echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';
User 377 answered question 1 INCORRECTLY. They entered the answer Fighter A.
User 377 answered question 1 INCORRECTLY. They entered the answer Fighter A.
User 55 answered question 1 INCORRECTLY. They entered the answer Fighter A.
User 88 answered question 1 CORRECTLY
User 945 answered question 1 INCORRECTLY. They entered the answer Fighter A.
User 2 answered question 1 INCORRECTLY. They entered the answer Fighter A.
User 967 answered question 1 INCORRECTLY. They entered the answer Fighter A.
User 377 answered question 2 INCORRECTLY. They entered the answer Fighter C.
User 377 answered question 2 INCORRECTLY. They entered the answer Fighter C.
User 55 answered question 2 INCORRECTLY. They entered the answer Draw.
User 88 answered question 2 CORRECTLY
User 945 answered question 2 INCORRECTLY. They entered the answer Fighter C.
User 2 answered question 2 CORRECTLY
User 967 answered question 2 INCORRECTLY. They entered the answer Fighter C.
User 377 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User 377 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User 55 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User 88 answered question 3 INCORRECTLY. They entered the answer Fighter F.
User 945 answered question 3 INCORRECTLY. They entered the answer Fighter E.
User 2 answered question 3 CORRECTLY
User 967 answered question 3 INCORRECTLY. They entered the answer Fighter E.
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);
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']][] = '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']][] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
}
}
}
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'] . ' ';
}
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();
}
}
?>
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;
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']][] = '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']][] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
}
}
}
$size_users = sizeof($users);
for($j = 0; $j < $size_users; $j++ )
{
echo '<strong>' . $users[$j]['name'] . '</strong>';
$size_users_answers = sizeof($users_information[$users[$j]]);
for($k = 0; $k < $size_users_answers; $k++ )
{
echo $users_information[$users[$j]][$k] . '<br />';
}
echo '<br /><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'] . ' ';
}
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();
}
}
?>
D
D
D
Code: Select all
for($j = 0; $j < $size_users; $j++ )
{
echo '<strong>' . $users[$j]['name'] . '</strong>';
$size_users_answers = sizeof($users_information[$users[$j]]);
for($k = 0; $k < $size_users_answers; $k++ )
{
echo $users_information[$users[$j]][$k] . '<br />';
}
echo '<br /><br />';
}
Code: Select all
print_r($users_information);