Page 5 of 12
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:20 am
by subvertbeats
Ok full output is:
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.
D
D
D
Array ( [377] => 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) ) [55] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 incorrect (Draw) [2] => Question 3 incorrect (Fighter F) ) [88] => Array ( [0] => Question 1 correct [1] => Question 2 correct [2] => Question 3 incorrect (Fighter F) ) [945] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 incorrect (Fighter C) [2] => Question 3 incorrect (Fighter E) ) [2] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 correct [2] => Question 3 correct ) [967] => Array ( [0] => Question 1 incorrect (Fighter A) [1] => Question 2 incorrect (Fighter C) [2] => Question 3 incorrect (Fighter E) ) )
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:23 am
by battye
What I'm trying to do is have it order it by user rather than by question. As you can see in that last section (Array([377....) it is working to an extent, it's just not got great formatting
Do you want me to persevere with this, or are you happy with it listing by question? (like the top of the output)
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:26 am
by subvertbeats
If you have the time then it would be great but I really dont want to take the mickey...
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:30 am
by battye
Okay then... 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;
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';
}
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'] . ')';
}
}
}
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'] . ' ';
}
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();
}
}
?>
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:32 am
by subvertbeats
Yep looking like its getting there
After the main result output...
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) ) )
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:37 am
by battye
Try:
FIND
BEFORE ADD
Code: Select all
for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
{
echo 'NAME: ' . $users[$j]['name'] . '<br />';
}
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:43 am
by subvertbeats
following the main output
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) ) )
If this is proving to be a headache, its definitely less important than updating the statistics tables
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:44 am
by battye
Okay, we'll move on to the stats then. I'm having dinner now so I'll be back online in 45 minutes.
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 10:49 am
by subvertbeats
Enjoy !
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 11:46 am
by battye
Okay, so what remains to be completed?
Is recording the statistics the only part?
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 11:53 am
by subvertbeats
I believe so yes
Other things are minor and I will try and tackle them over time.....
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 11:53 am
by battye
Okay
Did you comment out those lines in quiz.php that I mentioned in the other thread?
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 12:09 pm
by subvertbeats
The lines referenced here:
http://forums.cricketmx.com/viewtopic.p ... 195#p98998
?
If so, then yes, I have commented those four lines out.
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 12:23 pm
by battye
Yep, I made a mistake with one of them though. Can you leave this line uncommented:
Code: Select all
$statistical_sql[] = 'INSERT INTO ' . QUIZ_STATISTICS_TABLE . '
' . $db->sql_build_array('INSERT', $statistical_array);
Here's the new file:
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
$statistical_sql = 'INSERT INTO ' . QUIZ_STATISTICS_OVERVIEW_TABLE . '
' . $db->sql_build_array('INSERT', $statistical_overview_setup);
$db->sql_query($statistical_sql);
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();
}
}
?>
Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 12:33 pm
by subvertbeats
Thanks battye
Uncommented that line, then used your updated file for subvertbeats_quiz.php
SQL ERROR [ mysql4 ]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) VALUES' at line 2 [1064]
SQL
INSERT INTO phpbb_quiz_statistics_overview (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) VALUES (Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array, Array)
BACKTRACE
FILE: includes/db/mysql.php
LINE: 174
CALL: dbal->sql_error()
FILE: control_quiz.php
LINE: 110
CALL: dbal_mysql->sql_query()