I've just been following the "Database Searching" tutorial (http://betterphp.co.uk/playlist.html?pi ... 759BABE5EC) but unfortunately, every search seems to return an empty array.
Here is the code for my 'search.inc.php' in the tutorial this was the function file (blog_posts.inc.php)
function search_tags($term) {
$tags = preg_split('#\s+#', mysql_real_escape_string($term));
$sql = "SELECT * FROM wallpapers WHERE image_tags='$tags'";
$result = mysql_query($sql);
$results = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$results[] = $row;
}
return $results;
}
In my table 'wallpapers' I have a column for the images named, 'image_tags'. Inside of that column, the tags are displayed like so:I manually removed the spaces whilst I work on this project, I will eventually remove the spaces when the image is uploaded/submitted. But the tags will be separated by a comma for each image.city,tokyo,night
Sorry for rambling on. Back to to my error, here is my 'search.php' file
// My init.inc.php file is included above all of this
if (empty($_GET['term']) === false) {
$search_results = search_tags($_GET['term']);
if (empty($search_results)) {
echo 'Your search returned no results.';
}
foreach ($search_results as $search_result) {
echo '<img src="'.$search_result['thumb_path']."';
}
}
When for example, you search for either of the tags shown in the above quote (city, tokyo or night) the image isn't displayed.Any ideas where I could possibly be going wrong?
