-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
123 lines (101 loc) · 3.05 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
//try to establish a database connection
try {
//create new database object
$DbConn = new PDO(
'mysql:http://danu6.it.nuigalway.ie//;port=3306;dbname=mydb2463;',
'mydb2463ca',
'mi3tax',
array(PDO::ATTR_PERSISTENT => false)
);
//make the database layer throw exceptions on error
$DbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$DbConn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$DbConn->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$DbConn->query('SET NAMES "utf8"');
} catch (Exception $e) {
}
//get query from index.php - if blank it shouldn't error out
$fetch = isset($_GET["fetch"]) ? $_GET["fetch"] : '';
// search keywords by user input
$results = array();
try{
$STMT = $DbConn->prepare(
"SELECT station, csvLink, jsonLink, keyword
FROM DatasetInfo
WHERE MATCH ( keyword)
AGAINST ( :fetch IN NATURAL LANGUAGE MODE)"
);
$STMT->bindParam( 'fetch', $fetch, PDO::PARAM_STR );
$STMT->execute();
while( $result = $STMT->fetch( PDO::FETCH_ASSOC ) ){
//print print_r( $result,true );
$results[] = $result;
}
}
catch (Exception $e ) {
//print print_r( $e,true );
$results = array();
}
$num_results = count($results);
//print ( print_r( $results,true));exit();
?>
<!DOCTYPE html>
<html lang="en-IE">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width = device-width, initial-scale = 1">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<title>Marine Institute Results</title>
</head>
<body>
<div class="container">
<div class ="page-header">
<img src="Marine-Institutelogo.jpg">
</div>
<div class ="jumbotron">
<p>
<?php print $num_results;?> Result(s) Found.
<div class = "row">
<h1>Search Results</h1>
<div class = "col-md-6">
<table class="table table-bordered table-striped table-hover" id="productsTable">
<thead>
<tr>
<th>Station Location</th>
<th>CSV Data</th>
<th>JSON Data</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $results as $numResults => $result){
?>
<tr>
<td>
<?php print $result['station'];?>
</td>
<td>
<?php print '<a href="'.$result['csvLink'].'">CSV Data</a>';?>
</td>
<td>
<?php print '<a href="'.$result['jsonLink'].'">JSON Data</a>';?>
</td>
</tr>
<?php
} //endforeach
?>
</tbody>
</table>
</div>
</div>
</p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>
</body>
</html>