redirect( '/' ); } $num = $_REQUEST['num']; $mode = (isset($_POST['SUBMIT'])) ? 'a' : 'q'; $_POST['score'] = isset($_POST['score']) ? $_POST['score'] : 0; //use this seed to shuffle the order every day, then to prevent dups, //select entire set, then use $num to pull keep rows in order $seed = date('d'); $query = "select * from quiz order by rand($seed)"; $quiz_result = $db->query($query); $total_questions = $db->num_rows($quiz_result); //get out if num > total if ($num > $total_questions) { $gbl->redirect( '/quiz/thanks.html' ); } //figure out where next button should post to if ($num%3==20 && $mode=='a') { $formaction = '/quiz/thanks.html'; } elseif ($num==$total_questions && $mode=='a') { //no more questions available $formaction = '/quiz/thanks.html'; } elseif ($mode=='a') { $tempnum=$num+1; $formaction = '/quiz/question'.$tempnum; } else { $formaction = '/quiz/question'.$num; } $db->data_seek($quiz_result, $num-1); $quiz = $db->fetch_assoc($quiz_result); //now save trivia answer if being posted if ($mode=='a') { if ( preg_match("/[a-d]/", $_POST['user_answer'] )) { $fieldname = 'count_' . $_POST['user_answer']; $query = "UPDATE quiz set $fieldname = $fieldname+1 where id=".$quiz['id']." LIMIT 1"; $db->query($query); //now log the entry $_POST['timestamp'] = $gbl->INtime(); $_POST['ip'] = $_SERVER['REMOTE_ADDR']; $_POST['right_wrong'] = ($_POST['user_answer']==$quiz['right_answer']) ? 'r' : 'w'; //magic_quotes is off via .htaccess, so escape data before inserting $_POST = array_map($db->real_escape_string, $_POST); $query = "INSERT INTO quiz_log ( timestamp, ip, question_number, question_title, user_answer, right_wrong ) VALUES ( '$_POST[timestamp]', '$_POST[ip]', '$num', '$quiz[title]', '$_POST[user_answer]', '$_POST[right_wrong]' )"; $db->query($query); //update their score if ($_POST['user_answer']==$quiz['right_answer']) { $_POST['score']+=1; } } $total = $quiz['count_a']+$quiz['count_b']+$quiz['count_c']+$quiz['count_d']; $quiz['tally_a'] = round($quiz['count_a']/$total*100); $quiz['tally_b'] = round($quiz['count_b']/$total*100); $quiz['tally_c'] = round($quiz['count_c']/$total*100); $quiz['tally_d'] = round($quiz['count_d']/$total*100); } $gbl->page_title='Before They Were Famous Quiz'; //$gbl->meta_key=''; //$gbl->meta_desc=''; //$gbl->show_ads='top'; $gbl->getHeader(); $db->debug = 0; ?>
|
Question = $num ?>
Score: = $_POST['score'] ?> for = ($mode=='a') ? $num : $num-1 ?> |