function printArticleTable ($db_articles) {
global $db; // I'm accessing the $db from within the function.
?>
PEB Vol. |
Author |
Title |
View |
// Begin dodgy effort to get foreign key data into table
$db_bulletins = $db->get_results("select * from peb_bulletins ORDER BY year DESC, number");
$bulletins = array();
foreach ( $db_bulletins as $b ) {
$bulletins[$b->peb_id] = array ("year" => $b->year, "volume" => $b->volume, "number" => $b->number);
}
foreach ($db_articles as $a) {
print "";
print "".$bulletins[$a->peb_id]["year"].", ".$bulletins[$a->peb_id]["volume"]." (".$bulletins[$a->peb_id]["number"].") | ";
print "".$a->author." | ";
print "".$a->title." | ";
print "";
if ($a->abstract!=NULL) print " [ art_id\">View Abstract ] ";
if ($a->url!=NULL) print "[ url."\" target=\"_blank\">View PDF ] ";
print " | ";
print "
";
}
print "
";
}
/* SQL QUERY CLASS */
class sqlQuery {
// Just an object used to simplify building an sql query made of many 'AND' clauses... might get extended later.
var $select;
var $whereClauses = array();
var $orderBy;
function addSELECT($s) { $this->select = "SELECT ".$s." "; }
function addWHERE($clause) { array_push($this->whereClauses, $clause); }
function addORDERBY($s) { $this->orderBy = "ORDER BY ".$s; }
function sqlToString(){
$sqlOut = "".$this->select;
if (count($this->whereClauses)>0) {
$sqlOut .= "WHERE ";
$i = 0;
foreach($this->whereClauses as $c) {
$sqlOut .= $c;
$i++;
if ($i < count($this->whereClauses)) $sqlOut.=" AND ";
}
}
$sqlOut .= " ".$this->groupBY;
return $sqlOut;
}
}
?>
Search Bulletins
include "search_form.php";
$query = new sqlQuery; // Make a new query... Sven made this sqlQeury object.
$query->addSELECT("* FROM peb_articles");
if (isset($filterTable)) {
// They've chosen to filter their view... we just need to amend the sql query appropriately
if ($peb_id!="all") $query->addWHERE("peb_id=".$peb_id);
if ($article_type!="all") $query->addWHERE("type='$article_type'");
$searchText = split(" ",$search);
foreach($searchText as $s) {
$query->addWHERE("(author LIKE '%$s%' OR title LIKE '%$s%' OR abstract LIKE '%$s%')");
}
$query->addORDERBY("peb_id");
$sqlString = $query->sqlToString();
if ($selected_articles = $db->get_results($sqlString)) {
printArticleTable($selected_articles);
} else {
print "Search returned no results";
}
} else {
// They haven't searched for anything yet
print "";
}
?>