-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
96 lines (84 loc) · 3.15 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?
include "functions.inc";
include "theme.inc";
$theme->header();
dbconnect();
$terms = stripslashes($terms);
?>
<TABLE WIDTH="100%" BORDER="0">
<TR VALIGN="center">
<TD COLSPAN="3">
<FORM ACTION="<? print basename($GLOBALS[PHP_SELF]); ?>" METHOD="POST"><BR>
<INPUT SIZE="50" VALUE="<? print "$terms"; ?>" NAME="terms" TYPE="text"><BR>
<SELECT NAME="category">
<?
if ($category != "") print " <OPTION VALUE=\"$category\">$category</OPTION>";
print "<OPTION VALUE=\"\">All categories</OPTION>";
for ($i = 0; $i < sizeof($categories); $i++) {
print " <OPTION VALUE=\"$categories[$i]\">$categories[$i]";
}
?>
</SELECT>
<SELECT NAME="author">
<?
$result = mysql_query("SELECT aid FROM authors ORDER BY aid");
if ($author != "") print " <OPTION VALUE=\"$author\">$author";
print " <OPTION VALUE=\"\">All authors";
while(list($authors) = mysql_fetch_row($result)) {
print " <OPTION VALUE=\"$authors\">$authors";
}
?>
</SELECT>
<SELECT NAME="order">
<?
if ($order == "Oldest first") {
print "<OPTION VALUE=\"Oldest first\">Oldest first";
print "<OPTION VALUE=\"Newest first\">Newest first";
}
else {
print "<OPTION VALUE=\"Newest first\">Newest first";
print "<OPTION VALUE=\"Oldest first\">Oldest first";
}
?>
</SELECT>
<INPUT TYPE="submit" VALUE="Search">
</TD>
</TR>
<TR>
<TD>
<?
### Compose query:
$query = "SELECT DISTINCT s.sid, s.aid, s.subject, s.time FROM stories s, authors a WHERE s.sid != 0 ";
// Note: s.sid is a dummy clause used to enforce the WHERE-tag.
if ($terms != "") $query .= "AND (s.subject LIKE '%$terms%' OR s.introtext LIKE '%$terms%') ";
if ($author != "") $query .= "AND s.aid = '$author' ";
if ($category != "") $query .= "AND s.category = '$category' ";
if ($order == "Oldest first") $query .= " ORDER BY s.time ASC";
else $query .= " ORDER BY s.time DESC";
### Perform query:
$result = mysql_query("$query");
### Display search results:
print "<HR>";
while (list($sid, $aid, $subject, $time) = mysql_fetch_row($result)) {
$num++;
if ($user) {
$link = "<A HREF=\"article.php?sid=$sid";
if (isset($cookie[4])) { $link .= "&mode=$cookie[4]"; } else { $link .= "&mode=threaded"; }
if (isset($cookie[5])) { $link .= "&order=$cookie[5]"; } else { $link .= "&order=0"; }
if (isset($cookie[6])) { $link .= "&thold=$cookie[6]"; } else { $link .= "&thold=0"; }
$link .= "\">$subject</A>";
}
else {
$link = "<A HREF=\"article.php?sid=$sid&mode=threaded&order=1&thold=0\">$subject</A>";
}
print "<P>$num) <B>$link</B><BR><SMALL>by <B><A HREF=\"account.php?op=userinfo&uname=$aid\">$aid</A></B>, posted on ". date("l, F d, Y - H:i A", $time) .".</SMALL></P>\n";
}
if ($num == 0) print "<P>Your search did <B>not</B> match any articles in our database: <UL><LI>Try using fewer words.</LI><LI>Try using more general keywords.</LI><LI>Try using different keywords.</LI></UL></P>";
else print "<P><B>$num</B> results matched your search query.</P>";
?>
</TD>
</TR>
</TABLE>
<?
$theme->footer();
?>