// This is a function called by the main part of the program located below
$function get_options($List, $l2cf3721700722) {
// $List is set to either period, class or type which are also columns in the database
$Columns = “DISTINCT “.$List.”ID AS listoption”; // set the column to be retrieved as distinct period, class or type
$JavaList = “”; // created an empty string
if ($List == “period”) {
$OrderBy = “periodID”; // ORDER BY period
$Tbl = “sqltablemainidc”; // table to query
}
elseif ($List == “class”) { // if $List contains class
$Columns = $Columns.”, periodID”; // add period to the columns retrieved — Distinct class, period
$OrderBy = “periodID, listoption”; // add class to the sort — ORDER BY period, class
$Tbl = “classidc03072018”; // table to query
} elseif ($List == “type”) { // if $List contains type
$Columns = $Columns.”, classID”; // add class to the columns retrieved — Distinct type, class
$OrderBy = “classID, listoption”; // add class to the sort — ORDER BY class, type
$Tbl = ” typeidc03072018″; // table to query
}
$Query = “SELECT “.$Columns.” FROM “.$Tbl.” ORDER BY “.$OrderBy; // the query
// $Result = mysql_query($Query); // run the query
// if ($Result === FALSE) { // if an error occurred
// echo “ERROR Querering the database for “.$List.”s.
“;
// return(-1);
// }
$Options = “”.” “; // initialize the opstions string – first option will be blankforeach ($MyazDB->query($Query) as $O) {if ($O[“listoption”] == “?”or $O[“listoption”] == “period”) { // ignore bad datacontinue;}$Options = $Options.””.$O[“listoption”];// add the new option to the stringif ($List == “class”or $List == “type”) { // if $List contains either class or type, we are going to build another string// for use in the javascript. The string was initialize to an empty string above// now we are going to add a string of the period, “|”, class or type, “~”// I call this my pseudo array. This string will be hidden on the html form.if ($List == “class”) {$P = $O[“periodID”]; // get the period from the query} else {$P = $O[“classID”]; // get the class from the query}$JavaList = $JavaList.$P.”|”.$O[“listoption”].”^”; // add period and class/type to string}}$ReturnValues = array($Options, $JavaList); // create an array to return to the caller of this functionreturn($ReturnValues); // go back to the main logic}
// ——————-
// PROGRAM START —
// ——————-
error_reporting(E_ERROR | E_PARSE);
// =======================================================================
// Mya you need to change the following statement for your server <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//
// =======================================================================
// Connect to database
// statement below connects to your server you need to change it for your environment
// this is same as the workbench connect
// FALSE means there was an error
// =======================================================================
try {
$IDCDB = new PDO(“45.40.164.112″,”l2cf3721700722″,”dW{dV#3qpt=k”, “I2cf33721700722”);
} catch (PDOException $e) {
echo “ERROR Connecting to MySql server!
“;
return(-1); // returns to wordpress
}
// =======================================================================
$Periods = get_options(“period”, $l2cf3721700722); // go to the function above to get the periods
if ($Periods == -1) { // if the function returned an error end
return(-1);
}
$PeriodOptions = $Periods[0]; // the function returned an array. the first element a string of options
// to be used in the select. we ignore the second element of the array.
$Classes = get_options(“class”, $l2cf3721700722); // now go get the classes
if ($Classes == -1) {
return(-1);
}
$ClassOptions = $Classes[0]; // the string of all classes just to set up the class select on the form
$JavaClasses = $Classes[1]; // the pseudo array for java script which will be hidden on the form
$Types = get_options(“type”, $l2cf3721700722); // now get the types
if ($Types == -1) {
return(-1);
}
$TypeOptions = $Types[0]; // the string of all types just to set up the type select on the form
$JavaTypes = $Types[1]; // the pseudo array for javascript which will be hidden on the form
if (isset($_REQUEST[‘action’])
and $_REQUEST[‘action’] == “yesreturn”) { // we set yesreturn in the action on the form so if the submit button is
// clicked and the form comes back in we will get the items searched for
$SelPeriod = $_REQUEST[‘periodnm’]; // get the period selected on the form
if (is_null($SelPeriod)) {
$SelPeriod = ” “;
}
$SelClass = $_REQUEST[‘classnm’]; // class
if (is_null($SelClass)) {
$SelClass = ” “;
}
$SelType = $_REQUEST[‘typenm’]; // type
if (is_null($SelType)) {
$SelType = ” “;
}
$Query = “SELECT * FROM sqltablemainidc”.
” WHERE periodID = ‘”.$SelPeriod.”‘”.
” AND classID = ‘”.$SelClass.”‘”.
” AND typeID = ‘”.$SelType.”‘”.
” ORDER BY periodID, classID, typeID”;
$Result = $l2cf3721700722->query($Query);
$Rows = count($Result); // get the number of rows returned
$ReferenceSearch = array($Rows, $SelPeriod, $SelClass, $SelType); // put the selection criteria in an array
$ReferencesReturned = array();
if ($Rows > 0) {
$iRow = 0;
foreach($Result as $Row) { // get the rows from the database with column
$ReferencesReturned[] = $Row; // names and put in array
if (is_null($ReferencesReturned[$iRow][‘title’])
or $ReferencesReturned[$iRow][‘title’] == “NULL”) { // some of the columns show NULL. blank it out.
$ReferencesReturned[$iRow][‘title’] = ” “;
}
if (is_null($ReferencesReturned[$iRow][‘author’])
or $ReferencesReturned[$iRow][‘author’] == “NULL”) {
$ReferencesReturned[$iRow][‘author’] = ” “;
}
if (is_null($ReferencesReturned[$iRow][‘publications’])
or $ReferencesReturned[$iRow][‘publications’] == “NULL”) {
$ReferencesReturned[$iRow][‘publications’] = ” “;
}
if (is_null($ReferencesReturned[$iRow][‘language’])
or $ReferencesReturned[$iRow][‘language’] == “NULL”) {
$ReferencesReturned[$iRow][‘language’] = ” “;
}
$iRow = $iRow + 1;
}
}
}
mysql_close(); // done with the database so close the connection
?>
IDC SEARCH FORM