-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
67 lines (54 loc) · 2.55 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
<?php require_once("includes/session.php"); ?>
<?php $_SESSION['last_url'] = $_SERVER['PHP_SELF']; ?>
<?php require_once("includes/connections.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in(); ?>
<?php include("includes/header.php"); ?>
<?php include("includes/3ButtonNav.php"); ?>
<?php $user = $_SESSION['email']; ?>
<?php
$searchRequest = $_SERVER['REQUEST_METHOD'];
//echo $searchRequest;
if ($searchRequest = 'POST' && isset($_POST['search-term'])){
$searchTerm = $_POST['search-term'];
//echo $searchTerm;
}
else if ($searchRequest = 'GET' && isset($_GET['search'])){
$searchTerm = $_GET['search'];
//echo $searchTerm;
}
?>
<div class="container">
<div class="row">
<div class="span12">
<?php
$result = mysql_query("SELECT * FROM ideas WHERE (user='{$user}' AND (tags LIKE '%" . $searchTerm . "%' OR idea LIKE '%" . $searchTerm . "%' OR location LIKE '%" . $searchTerm . "%' OR month LIKE '%" . $searchTerm . "%' OR year LIKE '%" . $searchTerm . "%')) ORDER BY hits DESC", $connection);
if(!$result){
die("Database query failed: " . mysql_error());
}
if(mysql_num_rows($result) > 0) {
echo '<p class="muted bottomMargin">'.mysql_num_rows($result).' result(s) found for "<strong>' . $searchTerm . '</strong>".</p>';
echo '<div id="content">';
while ($row = mysql_fetch_array($result)){
$ideaTags = '';
$tags = explode(",", $row[6]);
foreach ($tags as $individualTag) {
$ideaLinkEndTag = ($individualTag == end($tags) ? '</a>' : '</a>, ');
$ideaTags .= '<a href="search.php?search='.trim($individualTag).'">'.$individualTag.$ideaLinkEndTag;
}
if($row[13] > 14){$sizeClass="bigIdea";}
else if($row[13] > 9 && $row[13] < 15){$sizeClass="mediumIdea";}
else if($row[13] < 10){$sizeClass="smallIdea";}
$completedClass = ($row[11]) ? 'completedIdeaRow' : 'inCompletedIdeaRow';
$completedDate = ($row[11]) ? ' <span class="ideaTimeDateCompleted"> (Completed on:'.$row[12].')</span> ' : '';
echo '<div hits="'.$row[13].'" class="box ideaRow '.$sizeClass.' '.$completedClass.'" onclick="javascript:window.location.href=\'idea.php?id='.$row[0].'\'"><span class="ideaBodyArchive">'.$row[2].'</span><span class="ideaTagsArchive">Tags: '.$ideaTags.'</span></div>';
}
}
else{
echo '<p class="text-error">Your search "<strong>' . $searchTerm . '</strong>" did not match any ideas.</p>';
}
?>
</div> <!--end of #content-->
</div>
</div>
<?php require("includes/footer.php"); ?>