4 ORDER BY rand() LIMIT 1"); $row = mysql_fetch_assoc ($result); extract ($row); $GamutName = ucfirst ($gamutName); //get specialties for selected gamut $result = mysql_query ("SELECT specialtyCode FROM SpecialtyRef WHERE entityID = $gamut"); //output specialties for selected gamut to a variable while ($row = mysql_fetch_assoc ($result)) { extract ($row); $listSpecialties .= "'$specialtyCode', "; } $listSpecialties=rtrim($listSpecialties, ", "); // TYPE 0 -- Identify the single cause of gamut if ($type == 0) { // Specify the question stem $question = "Which of the following can cause $gamutName?"; // Specify the SQL queries for the answer and distractors $distractors = "SELECT DISTINCT Candidate.cause, Candidate.name, 0 AS answer FROM (SELECT DISTINCT List.entity1 AS cause, E1.name FROM List, Entity AS E1, Entity AS E2, Source WHERE rel = 'C' AND E1.id = entity1 AND E2.id = entity2 AND E2.sourceID = Source.id AND topic = '$topic') AS Candidate LEFT JOIN (SELECT cause FROM ExpandedCause WHERE effect = $gamut) AS ExpCause USING ( cause ) WHERE ExpCause.cause IS NULL ORDER BY rand() LIMIT $numDistractors"; $answer = "SELECT DISTINCT entity1 AS cause, E1.name, 1 AS answer FROM List, Entity as E1, Entity as E2 LEFT JOIN Source ON E2.sourceID = Source.id WHERE rel = 'C' AND E1.id = entity1 AND E2.id = entity2 AND E2.sourceID = Source.id AND (E2.sourceID IS NULL OR Source.approved IS NOT NULL) AND entity2 = $gamut ORDER BY rand() LIMIT 1"; } // TYPE 1 -- Identify the one NON-cause of the gamut else { // type == 1 // Specify the question stem $question = "Which of the following does NOT cause $gamutName?"; // Specify the SQL queries for the answer and distractors $distractors = "SELECT DISTINCT entity1 AS cause, E1.name, 0 AS answer FROM List, Entity as E1, Entity as E2, Source WHERE rel = 'C' AND E1.id = entity1 AND E2.id = entity2 AND E2.sourceID = Source.id AND entity2 = $gamut ORDER BY rand() LIMIT $numDistractors"; $answer = "SELECT DISTINCT Candidate.cause, Candidate.name, 1 AS answer FROM (SELECT DISTINCT List.entity1 AS cause, E1.name FROM List, Entity AS E1, Entity AS E2, Source WHERE rel = 'C' AND E1.id = entity1 AND E2.id = entity2 AND E2.sourceID = Source.id AND (E2.sourceID IS NULL OR Source.approved IS NOT NULL) AND topic = '$topic') AS Candidate LEFT JOIN (SELECT cause FROM ExpandedCause WHERE effect = $gamut) AS ExpCause USING ( cause ) WHERE ExpCause.cause IS NULL ORDER BY rand() LIMIT 1"; } // Compose overall query $result = mysql_query ( "SELECT cause, name, answer FROM ( ($distractors) UNION ($answer) ) AS Options ORDER BY rand() "); // Display the stem stem ($gamut, $gamutName, $question, $type, $topic); // Display the options while ($row = mysql_fetch_assoc ($result)) { extract ($row); $name = ucfirst ($name); option ($cause, $name, $answer); } } function quiz_cause ($id, $type, $numDistractors) { $gamutSQL = ( $id == '' ? "1" : mysql_real_escape_string ("entity2 = $id")); // Randomly select an entity that appears in at least 5 gamuts $result = mysql_query ( "SELECT entity1 AS cause, Entity.name AS causeName, topic, count(*) AS numCauses FROM List, Entity, Source WHERE $causeSQL AND rel = 'C' AND entity1 = Entity.id AND Entity.sourceID = Source.id GROUP BY entity1 HAVING numCauses > 4 ORDER BY rand() LIMIT 1"); $row = mysql_fetch_assoc ($result); extract ($row); $CauseName = ucfirst ($causeName); if ($type == 2) { $question = "$CauseName does NOT cause:"; } else { $question = "Which of the following is caused by $causeName?"; } stem ($cause, $causeName, $question, $stemType, $topic); // Select answer and distractors $result = mysql_query ( "SELECT gamut, name, answer FROM ((SELECT DISTINCT entity2 AS gamut, E2.name, 0 AS answer FROM List, Entity as E1, Entity as E2, Source WHERE rel = 'C' AND E1.id = entity1 AND E2.id = entity2 AND E2.sourceID = Source.id AND $wrong ORDER BY rand() LIMIT $numDistractors) UNION (SELECT entity2 AS gamut, E2.name, 1 AS answer FROM List, Entity as E1, Entity as E2, Source WHERE rel = 'C' AND E1.id = entity1 AND E2.id = entity2 AND E2.sourceID = Source.id AND $right GROUP BY entity2 ORDER BY rand() LIMIT 1)) AS Options ORDER BY rand() "); //$countRecords = mysql_num_rows($result); //echo "

count: $countRecords

"; while ($row = mysql_fetch_assoc ($result)) { extract ($row); option ($gamut, ucfirst ($name), $answer); //echo "

$gamut :: $name :: $answer

"; } } function stem ($id, $name, $question, $stemType, $topic) { global $item; $item ['stem'] = array ( 'id' => $id, 'name' => $name, 'question' => $question, 'type' => $stemType, 'topic' => $topic ); } function option ($id, $name, $answer) { global $item; $item ['option'] [] = array ( 'id' => $id, 'name' => $name, 'answer' => $answer ); //echo "

$id :: $name :: $answer

"; } ?> Quiz | Gamuts.net "; //print_r($item); //print_r($checkItem); //echo ""; ?>

Gamuts Quiz Question

"; $str = $cause." ".$answer." ".$name; $str = base64_encode($str); echo ""; echo "
"; ++ $i; } ?>
Select the one best answer.
Try another quiz question.