-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchGroup.php
96 lines (77 loc) · 2.54 KB
/
searchGroup.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
<?php
if(!defined('includeConst')) { die('Direct access not permitted'); }
if (isset($_GET['a']) && $_GET['a'] == "search") {
showSearchResults($db, $userName, $group, $role);
} else {
showSearchForm($userName, $group, $role);
}
function showSearchForm($userName, $group, $role) {
?>
<body>
<main class="filters">
<?php include "header.inc"; ?>
<div class="two">
<h1>Find A Group</h1>
<form id="searchForm" action="?page=groupSearch&a=search" method="POST">
<label for="fieldSelect">Preferred Project Type</label><br>
<select name="field" id="fieldSelect">
<option value="">Any</option>
<option value="Web Development">Web Development</option>
<option value="Programming">Programming</option>
<option value="Project Leadership">Design</option>
<option value="Business">Business</option>
</select>
<br><br>
<input type="submit" value="search"/>
</form>
</div>
<?php include 'footer.php' ?>
</main>
</body>
</html>
<?php
} //end ShowSearchForm
function showSearchResults($db, $userName, $group, $role) { ?>
<?php
$mainArea = $_POST['field'];
if($mainArea == "") {
$query = ('SELECT * FROM groups');
}
else {
$query = ('SELECT * FROM groups WHERE projectType = :mainArea');
}
$statement = $db -> prepare($query);
$statement -> bindValue(':mainArea', $mainArea);
if (!$statement -> execute()) {
print_r($statement->errorInfo());
return false;
} else {
$result = $statement -> fetchAll(PDO::FETCH_ASSOC);?>
<body>
<main>
<?php include "header.inc"; ?>
<div class="content">
<h1>Search Results</h1>
<table>
<tr>
<th>Name</th>
<th>Preferred Project Type</th>
<th>Actions</th>
</tr>
<?php foreach ($result as $row) { ?>
<tr>
<td><?=$row['name']?></td>
<td><?=$row['projectType']?></td>
<td><a class="button" href="/?page=group&action=addMeToExisting&group=<?=$row['id']?>">Join Group</a></td>
</tr>
<?php } ?>
</table>
</div>
</main>
</body>
</html>
<?php
}
?>
<?php }
?>