<?php

include("lib/db.inc");
extract($_GET);

//echo "here";

$sql = "select n.title, n.nid, n2.title as title, quiz_nid, alias 
from node n 
join opigno_quiz_app_quiz_sort o on o.gid = n.nid 
join node n2 on n2.nid = quiz_nid 
join url_alias u on u.source like concat('%',quiz_nid) 
where upper(n.title) like upper('%$subject%$grade%Term%$term%')";

//$num_rows = $data->

$data->execSQL($sql);
$result = array();
while($row = $data->getRow())
{
	$result[] = $row;
}


$result = json_encode($result);
$output = base64_encode(gzdeflate($result, 9));
//$output = rtrim(strtr(base64_encode(gzdeflate($result, 9)), '+/', '-_'), '=');
echo $output;

/*echo "<hr/>";
$output =  gzinflate(base64_decode($output));
//$output = gzinflate(base64_decode(strtr($$output, '-_', '+/')));
echo $output;*/
?>