//If you have a working PHPLIB installed, you might want to enable all
// of the session-related lines in this file, as that will make several
// additional features possible (such as variable number of conditions and
// the next/prev buttons)
require "special_query.inc";
require "enz_db.inc";
page_open( array("sess" => "Poe_Session" ));
require("c_timer.inc");
$timer = new c_Timer;
$timer->start();
function getSelectQuery( $name )
{
switch ($name )
{
case "s_classname":
$t1 = new SQL_Cond( "enzclass", "classname" );
return new SQL_Select( $t1 );
case "s_funcname":
$t1 = new SQL_Cond( "enzclass", "enzclassid", "=",
"enzclass_enzfunc", "enzclassid" );
$t2 = new SQL_Cond( "enzclass_enzfunc", "enzfuncid", '=',
"enzfunc", "enzfuncid" );
$t3 = new SQL_Cond( "enzfunc", "funcname" );
return new SQL_Select( $t1->sand( $t2->sand($t3) ) );
case "s_varname":
$t1 = new SQL_Cond( "enzclass", "enzclassid", "=",
"enzclass_enzvar", "enzclassid" );
$t2 = new SQL_Cond( "enzclass_enzvar", "enzvarid", '=',
"enzvar", "enzvarid" );
$t3 = new SQL_Cond( "enzvar", "name" );
return new SQL_Select( $t1->sand( $t2->sand( $t3 ) ) );
}
}
require "SQL_Select.inc";
require( "../../EnzymeTemplates/display_student.inc" );
include( "enz_objects.inc" );
// When we hit this page the first time,
// there is no $sq.
if (!isset($sq) || isset($clear))
{
$sq = new Special_Query( "", "form_layout.ihtml" ); // We make one
$sq->conditions = 2; // ... with TWO conditions (at first)
$sq->variable = "on"; // ... # of conditions is variable
$sq->lang = "easy_en"; // ... in EASY TO UNDERSTAND English, please
$sq->method = "GET";
$sq->use_images = 0;
$sq->what_to_select = "enzclass.enzclassid";
$sess->register("sq"); // and don't forget this!
}
$sq->default_sql = new SQL_Select( new SQL_Cond( "enzclass","enzclassid",">","0"));
// In any case we must display that form now. Note that the
// "x" here and in the call to $q->where must match.
// Tag everything as a CSS "query" class.
//strings that begin with s_ are names of SQL_Select objects and are
//defined in setup_queries.inc
$op = array( "s_classname" => "Class",
"s_funcname" => "Function",
"s_varname" => "Variable"
);
$sq->form("x", $op, "query");
// When we hit that page a second time, the array named
// by $base will be set and we must generate the $query.
// in this case, the data from the form is all posted to $x
if (isset($x))
{
// extract the data from $x into a SQL_Select object
$Sql = $sq->getSelect("x", 1 );
$Sqlcount = $sq->getCountSelect("x", 0);
}
if ($Sql)
{
// at this point we have 2 different SQL_Select objects
// one to get the count and one to do the query. This is sub-optimal
printf( "\nTo get the count I would query:
%s
\n",
$Sqlcount->toString() );
$db = new DB_Enz;
$result = $db->query( $Sqlcount->toString() );
$db->next_record();
$num_results = $db->num_rows();
printf( "\nTo get the actual results, I would query:
%s
\n",
$sql_string = $Sql->toString() );
$result = $db->query( $sql_string );
$query_results = $db->num_rows();
$sq->query_count = $query_results;
if( $num_results )
{
$result_string = sprintf( "Showing results %d to %d", $sq->iFirst+1, min( 0+$num_results, $sq->iLast ));
$result_string .= " (of $num_results)";
}
else
{
$result_string = "No matches to your query";
}
printf( "%s
", $result_string );
while( $db->next_record() )
{
$sid = $db->f( "enzclassid" );
$stud = new Enzclass( $sid );
$stud->printShort();
$count++;
}
}
$timer->stop();
echo "Time elapsed: ".$timer->elapsed()."
";
page_close();
?>