Fixed search - it actually works now!

This commit is contained in:
tcourage 2016-04-07 13:10:39 -04:00
parent 6c0e88f4e7
commit b1664f0af3
3 changed files with 24 additions and 18 deletions

View File

@ -1,6 +1,6 @@
# Meme Machine
## Current Version: v0.3.5-beta
## Current Version: v0.3.6-beta
## Overview
@ -16,6 +16,11 @@ Users are then able to browse the memes using the categories, and in future vers
## Changelog
### v0.3.6-beta - April 7, 2016
- Fixed critical issue where searches wouldn't work
- Added fancy new details section on landing page
### v0.3.5-beta - April 7, 2016
- Categories are now a drop-down box rather than an incoherent table

View File

@ -20,26 +20,22 @@ echo '<h1>Meme Machine</h1>';
} else {
}
$term = $_POST['term'];
$words = $_POST['term'];
$tokens = explode(' ', $term);
$tokens = array_map(
function($term) {
return mysqli_real_escape_string(trim($term));
},
$tokens
);
$parts=explode(" ",trim($words));
$clauses=array();
foreach ($parts as $part){
$clauses[]="'%" . $part . "%'";
}
$clause .= implode(' OR ' ,$clauses);
$sql = "SELECT * FROM memes WHERE name LIKE '$term";
$sql .= implode("%' or name LIKE '%", $tokens) . "'";
if(isset($_POST['search']) && $term){
echo "You searched for: " . $term . "<br />";
$sql = "SELECT * FROM memes WHERE name LIKE $clause OR category LIKE $clause";
if(isset($_POST['search']) && $words){
echo "You searched for: " . $words . "<br />";
$result = mysqli_query($conn, $sql);
echo $sql;
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$count++;
@ -65,8 +61,8 @@ echo '<h1>Meme Machine</h1>';
<a href="./">Back</a>
<?php
}
echo '<br>';
echo '<a href="./">Back</a>';
echo '</body>';
echo '</html>';
?>

View File

@ -1,3 +1,8 @@
<!--
The Meme Machine - An open source image databasing system
A project by Taylor Courage (http://taylorcourage.net)
Latest Release: v0.3.6-beta (April 7, 2016)
-->
<html>
<head>
<title>Meme Machine</title>
@ -98,6 +103,6 @@
<br />
<br />
<br />
<h6>Meme Machine v0.3.5-beta</h6>
<h6>Meme Machine v0.3.6-beta</h6>
</div>
</html>