$num_pages) { $page = 1; } $start = ($page*$per_page) - $per_page; $end = ($start + $per_page) - 1; if ($page == $num_pages) { $cur_records = $per_page*($num_pages-1); $per_page = $numRecords - $cur_records; $end = ($cur_records + $per_page) - 1; } $pagination_vars = array("page" => $page, "start" => $start, "end" => $end, "num_pages" => $num_pages); return $pagination_vars; } // ############################################################# function generate_navigation ($num_pages, $page, $url) { if ($page != 1) { echo '« Previous · '; } else { echo '« Previous · '; } for ($x = 1; $x <= $num_pages; $x++) { if ($page == $x) { echo ' ' . $x . ' '; } else { echo ' ' . $x . ' '; } if($num_pages == $x) { // } else { echo '| '; } } if ($page == $num_pages) { echo '· Next »'; } else { echo '· Next »'; } } // ################################################################# ?> James Alexander Glazier - Home Page - Papers: Search
Indiana University Department of Physics - James A. Glazier

Search Papers


Query:

Restrict Search to Category and/or Field [default: all categories, by title]:
'; db_connect ($dbhost, $dbuser, $dbpass); $result = db_select_allb('categories', 'ORDER BY CategoryID ASC', 'Category, CategoryID'); list_categories($result, NULL); mysql_close(); gen_search_by(NULL); echo '

Sort Results by:
'; gen_sort_by(NULL, NULL); echo '



'; } // ######################################### SEARCH PAPERS elseif ($_GET['action'] == "sp") { $table = 'papers'; if(isset($_GET['query']) && $_GET['query'] != "") { $query = ltrim(rtrim(substr($_GET['query'], 0, 512))); $field = rtrim(substr($_GET['spfield'], 0, 12)); $papersort = rtrim(substr($_GET['psort'], 0, 12)); $sort = rtrim(substr($_GET['sort'], 0, 4)); $category = rtrim(substr($_GET['cat'], 0, 8)); } elseif(!isset($_POST['query']) or $_POST['query'] == "") { echo 'You did not enter a query. Please go back and enter a query.'; exit(); } else { $query = ltrim(rtrim(substr($_POST['query'], 0, 512))); $field = rtrim($_POST['SearchPaperField']); $papersort = rtrim($_POST['PaperField']); $sort = rtrim($_POST['Sort']); $category = rtrim($_POST['CategoryID']); } if ($category == -1) { $category = 'all'; } if ($papersort == -1) { $papersort = 'PaperTitle'; } if (!preg_match("/^\w+(\s\w+)*\w*$/", $query)) { die('

Illegal characters in the query. Only alpha-numeric characters are allowed.

'); } validate_input($field, 'search paper field'); validate_input($papersort, 'sort by category field'); validate_input($sort, 'sort by field'); validate_input($category, 'category'); db_connect ($dbhost, $dbuser, $dbpass); if($category == 'all') { $data = mysql_query("SELECT ID FROM $table WHERE $field LIKE '%$query%' ORDER BY $papersort $sort"); } else { $data = mysql_query("SELECT ID FROM $table WHERE CategoryID = '$category' AND $field LIKE '%$query%' ORDER BY $papersort $sort"); } $numRows = mysql_num_rows($data); $pvars = page_vars($numRows, $per_page, $page); if($numRows != 0) { if($category == 'all') { $data = mysql_query("SELECT PaperTitle, Citation, PaperNo, LinkNo, ImgURL, CategoryID, ID FROM $table WHERE $field LIKE '%$query%' ORDER BY $papersort $sort LIMIT " . $pvars['start'] . ", $per_page"); } else { $data = mysql_query("SELECT PaperTitle, Citation, PaperNo, LinkNo, ImgURL, CategoryID, ID FROM $table WHERE CategoryID = '$category' AND $field LIKE '%$query%' ORDER BY $papersort $sort LIMIT " . $pvars['start'] . ", $per_page"); } echo '

Found ' . $numRows . ' result(s). Displaying result(s) ' . ($pvars['start']+1) . ' through ' . ($pvars['end']+1) . '. [ New Query ]


'; echo '
'; generate_navigation($pvars['num_pages'], $pvars['page'], "search.php?action=sp&query=" . $query . "&spfield=" . $field . "&cat=" . $category . "&sort=" . $sort . "&psort=" . $papersort . "&"); echo '


'; // ########## /*if($category == 'all') { $data = mysql_query("SELECT PaperTitle, Citation, PaperNo, CategoryID, ID FROM $table WHERE $field LIKE '%$query%' ORDER BY $papersort $sort LIMIT " . $pvars['start'] . ", $per_page"); } else { $data = mysql_query("SELECT PaperTitle, Citation, PaperNo, CategoryID, ID FROM $table WHERE CategoryID = '$category' AND $field LIKE '%$query%' ORDER BY $papersort $sort LIMIT " . $pvars['start'] . ", $per_page"); }*/ while ($row = mysql_fetch_array($data)) { // generat search results -- same format as when browsing by category if ($row['LinkNo'] != '' or $row['LinkNo'] != NULL) { $link = 'Download PDF | PS '; } else { $link = ''; } if ($row['ImgURL'] != '' or $row['ImgURL'] != NULL) { $image = '
'; } else { $image = ''; } echo '
' . $row['PaperTitle'] . ' [' . $row['PaperNo'] . ']
' . $row['Citation'] . '
' . $link . ' ' . $image . '


'; /*echo '
' . $row['PaperTitle'] . '
[' . $row['PaperNo'] . '] ' . $row['Citation'] . '


'; */ } // end loop // add navigation at bottom echo '
'; generate_navigation($pvars['num_pages'], $pvars['page'], "search.php?action=sp&query=" . $query . "&spfield=" . $field . "&cat=" . $category . "&sort=" . $sort . "&psort=" . $papersort . "&"); echo '


'; //########################################### mysql_close(); } else { echo '

No results found. If you would like, go back and refine your search criteria.'; } } // ################################################################################################################# ?>