-inserted a search button into board.php

-added a search page in which the results are shown
This commit is contained in:
Ismail Cadaroski 2017-02-27 20:13:15 +01:00
parent e25dbdb8d2
commit f0aeba0a02
3 changed files with 69 additions and 0 deletions

View File

@ -32,7 +32,15 @@ date_default_timezone_set('Europe/Amsterdam');
</div>
<!-- The Post function begins here -->
<div>
<div>
<h2>Open Demands</h2>
<form action='search_demand.php' method='POST' >
<input type ="text" name = "search" placeholder="search">
<button type ="submit" name="submit-search">Search</button>
</form>
</div>
<?php
get_demand_titles($con);
?>

View File

@ -166,4 +166,5 @@ function delete_demand()
header('Location: board.php');
}
}
?>

60
search_demand.php Normal file
View File

@ -0,0 +1,60 @@
<?php
include 'functions.php';
date_default_timezone_set('Europe/Amsterdam');
?>
<!DOCTYPE html>
<html>
<head>
<!-- enable utf-8 encoding for umlauts etc.-->
<meta charset="utf-8">
<!-- Description of what this dose -->
<meta name ="viewport" content="width=device-width, initial-scale=1">
<!-- link to the default css file -->
<link rel="stylesheet" href="css/stylesheet.css"/>
</head>
<body>
<div>
<div>
<header>
<!-- The title begins here -->
<h1>Search Page</h1>
<!--The Title ends here -->
<!-- The sidebar naviagtion begins here -->
<nav>
<?php
include 'navigation.php';
?>
</nav>
<!-- The sidebar naviagtion ends here -->
</header>
<div class= "">
<?php
if (isset($_POST['submit-search'])) {
global $con;
$search = mysqli_real_escape_string($con, $_POST['search']);
$sql = "SELECT * FROM demands WHERE demandTitle LIKE '%$search%'
OR demandText LIKE '%$search%'";
$result= mysqli_query($con, $sql);
$queryResult = mysqli_num_rows($result);
if($queryResult > 0) {
while($row = mysqli_fetch_assoc($result)){
echo "<div class='post-box'><p>";
echo "<strong>" . $row['demandTitle'] . "</strong>" . "<br>";
echo $row['date'] . "<br>";
echo "</p>
</div>";
}
}else{
echo "There are no results matching your search!";
}
}
?>
</div>
</div>
</body>
</html>