Skip to content
Snippets Groups Projects
Commit 53a79d50 authored by Silas Meister's avatar Silas Meister
Browse files

Enable searching and display results

parent f80ead03
Branches
No related tags found
No related merge requests found
...@@ -49,10 +49,27 @@ function fetchNews(searchWord) { ...@@ -49,10 +49,27 @@ function fetchNews(searchWord) {
} }
function displaySearchResults(json) { function displaySearchResults(json) {
let searchResults = document.getElementById(); const searchResults = document.getElementById('search-results');
searchResults.innerText = "";
json.forEach((news) => { json.forEach((news) => {
console.log(news['title']); let child = createNewsChild(news);
searchResults.appendChild(child);
}); });
const display = json.length === 0 ? "none" : "block";;
searchResults.style.display = display;
}
function createNewsChild(news) {
let a = document.createElement('a');
let textNode = document.createTextNode(news['title']);
a.appendChild(textNode);
return a;
} }
function slideImage() { function slideImage() {
......
...@@ -68,8 +68,7 @@ class Index extends Page { ...@@ -68,8 +68,7 @@ class Index extends Page {
<input id="search-input" name="search-input" type="search" placeholder="Search" /> <input id="search-input" name="search-input" type="search" placeholder="Search" />
<input id="search-button" type="button" value="" /> <input id="search-button" type="button" value="" />
</form> </form>
<div class="search-results"> <div id="search-results">
<p>sdfdsfsdfasfdasfasfas</p>
</div> </div>
</li> </li>
<li><img src="../img/share_icon.png" alt="" /></li> <li><img src="../img/share_icon.png" alt="" /></li>
......
...@@ -26,9 +26,12 @@ class NewsFetch extends Page ...@@ -26,9 +26,12 @@ class NewsFetch extends Page
{ {
$data = array(); $data = array();
if (empty(trim($this->searchWord)))
return $data;
$likeSearchWord = "%" . $this->searchWord . "%"; $likeSearchWord = "%" . $this->searchWord . "%";
$stmt = $this->database->prepare("SELECT n.title FROM news n WHERE n.title LIKE ? LIMIT 5"); $stmt = $this->database->prepare("SELECT n.title FROM news n WHERE LOWER(n.title) LIKE LOWER(?) LIMIT 5");
$stmt->bind_param("s", $likeSearchWord); $stmt->bind_param("s", $likeSearchWord);
$stmt->execute(); $stmt->execute();
$resultSet = $stmt->get_result(); $resultSet = $stmt->get_result();
......
...@@ -113,7 +113,8 @@ a { ...@@ -113,7 +113,8 @@ a {
cursor: pointer; cursor: pointer;
} }
.search-results { #search-results {
display: none;
position: absolute; position: absolute;
background-color: #333333; background-color: #333333;
opacity: 0.9; opacity: 0.9;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment