1)&&($currmonth<6)){ $semester='Spring'; }elseif (($currmonth>5)&&($currmonth<9)){ $semester='Summer'; }else{ $semester='Fall'; } $order=" ORDER BY dept"; $where = " WHERE year='$year' AND semester='$semester'"; $query = "SELECT * from courses"; } include("searchform.html"); if ($search) { // they have submitted the search form $query = "SELECT * from courses"; $where = " WHERE"; $order = " ORDER BY id"; } // initialize offset and rows values if (!isset($HTTP_GET_VARS["offset"])) $offset=0; if (!isset($rows)) $rows=100; /* ----------------------------------------------------------------- */ // BUILD SQL QUERY /* ----------------------------------------------------------------- */ if ($year) { if ($where == " WHERE") $where .= " year=$year"; else $where .= " AND year=$year"; } if ($semester) { if ($where == " WHERE") $where .= " semester='$semester'"; else $where .= " AND semester='$semester'"; } if ($dept) { if ($where == " WHERE") $where .= " dept='$dept'"; else $where .= " AND dept='$dept'"; } if ($code) { if ($where == " WHERE") $where .= " LCASE(code) LIKE LCASE('%$code%')"; else $where .= " AND LCASE(code) LIKE LCASE('%$code%')"; } if (($year) && ( !$semester) && (!$dept)){ $order=" ORDER BY semester,dept"; } if ((!$year) && ( !$semester) && ($dept)){ $order=" ORDER BY year"; } /* ----------------------------------------------------------------- */ // GET NUMBER OF RESULTS /* ----------------------------------------------------------------- */ // query the server $r = db_query($query . $where); // we want to get a total number of results $tnum=db_num_rows($r); $limit = " LIMIT ".$offset.",".$rows; $r = db_query($query . $where . $order . $limit); $num = db_num_rows($r); /* ----------------------------------------------------------------- */ // PRINT OUT NEXT/PREV LINKS & PAGE NUMBERS /* ----------------------------------------------------------------- */ ?> $value) { // build a query string so that our search info is saved if ($name=="offset") continue; // don't include this - we'll set it later if ($q != '') $q .= "&"; if ($name=="dept") {$dept=rawurlencode($dept); $q .= "dept=$dept"; $dept=rawurldecode($dept); continue;} $q .= "$name=$value"; } //table for prev and next links $np .= "\n
\n"; $np .= "
\n"; $np .= "
"; if ($rows != 0) $pages = (integer) ($tnum / $rows); // how many pages? if ($tnum % $rows) $pages++; // in case we have a partial page - // integer type casting rounds down if ($pages ==1) $pages=0; // if we only have one page, skip this step $noffset=0; for ($i=0;$i<$pages;$i++) { $noffset=$i * $rows; // get the offset for the page // as long as the current offset doesn't match the page offset, print out a link if ($noffset != $offset) $np .= ""; $np .= $i+1; if ($noffset != $offset) $np .= ""; if ($i % 20 == 0 && $i !=0) $np .="
"; // every n items, put in a new line $np .= " "; } $np .="
"; // only display the "prev" link if we are not on the first page (offset=0) if ($offset !=0) $np .= ""; $np .= "<< PREV"; if ($offset !=0) $np .=" "; $np .= " | "; // now we want to query the server as if we were requesting the next page and check how many rows it // returns. Next check how many potential pages of data we have to display and print out a list $nlimit = " LIMIT " . ($offset+$rows) . "," . $rows; $res = db_query($query . $where . $nlimit); // print out the "next" link only if we have more rows to display $x=db_num_rows($res); if ($x) $np .= ""; $np .= "NEXT >>"; if ($x) $np .= ""; //end of prev and next table $np .= "
"; $np .= "

"; //end // intialize our color thingy: $color=0; /* ----------------------------------------------------------------- */ // PRINT OUT SEARCH RESULTS /* ----------------------------------------------------------------- */ // query the server again, since our previous results were overwritten // by the next/prev link operation $r = db_query($query . $where . $order . $limit); //$r = db_query($query); // this is the table that surrounds our entire search results section print "
\n"; print "
\n"; print "SQL: $query$where$order$limit
"; print "

Search Results:
"; $nrows = ($num < $rows)? $num : $rows; if ($tnum != 0) print "Displaying results ".($offset+1) ."-".($offset+$nrows)." of $tnum results.

"; else print "No matching results were found.

"; if ($num > 0) { // print out one occurenct of the next/prev links print $np; print "
"; print "\n"; print "
"; print "
"; print "

".$semester." ".$year."

"; print "
"; $nextdept = ""; $nextsem = ""; $nextyear = ""; print "
"; if ((!$year) && ( !$semester) && ($dept) && (!$code)) { print "

".$dept."

"; }else{ if ($code){ print "

".$code."

"; }elseif ($dept){ print "

".$dept."

"; } } print "

"; while ($a = db_fetch_assoc($r)) { $url = urldecode ($a['url']); if (($year) && ( !$semester) && (!$dept)){ print "\n"; print "\n"; print "\n"; } else { print "\n"; } print "\n"; print "\n"; } else { print "\n"; } print "\n"; } else { print "\n"; } print ""; print "\n"; }elseif ((!$year) && ( !$semester) && (!$dept) && ($code)){ if ($nextyear != $a['year']){ $color="grey"; } else { $color=""; } if ($color){ print "\n"; } else { print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } // end while print "
\n"; print $a['semester']; print "\n"; if ($nextdept != $a['dept']) { print $a['dept']; $nextdept = $a['dept']; } else { print " "; } } elseif ((!$year) && ( !$semester) && ($dept)) { if (($nextyear != $a['year']) || ($nextsem != $a['semester'])){ $color="grey"; } else { $color=""; } if ($color){ print "
\n"; if (($nextyear != $a['year']) || ($nextsem != $a['semester'])) { print $a['year']; } else { print " "; } print "\n"; if (($nextsem != $a['semester'])|| ($nextyear != $a['year'])) { print $a['semester']; $nextsem = $a['semester']; if ($nextyear != $a['year']) { $nextyear = $a['year'];} } else { print " "; } }elseif ((!$year) && ($semester) && ($dept)){ if ($nextyear != $a['year']){ $color="grey"; } else { $color=""; } if ($color){ print "
\n"; if (($nextyear != $a['year']) && ($nextsem != $a['semester'])) { print $a['year']; } else { print " "; } if ($nextyear != $a['year']) { $nextyear = $a['year']; } else { print " "; } }elseif ((!$year) && ($semester) && (!$dept)){ $id = $a['id']; if ($nextyear != $a['year']){ $color="grey"; } else { $color=""; } if ($color){ print "
\n"; if ($nextyear != $a['year']) { print $a['year']; } else { print " ";} print "\n"; if (($nextyear != $a['year']) && ($nextdept != $a['dept'])) { print $a['dept']; $nextyear=$a['year']; } else { print " "; } }elseif (($year) && (!$semester) && ($dept)){ print "
\n"; if ($nextyear != $a['year']) { print $a['year']; }else{ print " "; } print "\n"; if (($nextsem != $a['semester']) || ($nextyear != $a['year'])) { print $a['semester']; $nextsem = $a['semester']; $nextyear=$a['year']; }else { print " "; } }else{ $id = $a['id']; print "
\n"; if ($nextdept != $a['dept']) { print $a['dept']; $nextdept = $a['dept']; } else { print " "; } } print "\n"; print "".$a['code']." - ".$a['title'].""; if ($ltype == 'admin'){ print "
Edit "; } print "
 
"; print $np; ?>
"; // end the surrounding table print "
"; print "
"; include("searchform.html"); ?>