searching mysql
Posted: Sun Apr 26, 2009 10:55 am
Hey,
I have setup my own search on my games website, it searches keywords that I store in my database under the name 'tags'.
Now... If I store a 'tag' as say pacman, and search 'pacman' it comes up, but if I search 'pacman game' it doesn't find it because I only stored it as 'pacman'. So what I want help with really is setting it so that the search results don't have to be so specific, any one of the search keywords are found under 'tag' in the DB it will show the results...
My code is something like this:
http://www.zippygame.com try the search, if you search 'pacman' you will see a result because i only stored the keyword 'pacman' in the mysql database. Where as if you search 'super' you will get nothing as I stored the keywords 'super mario world' so you would have to search the full 'super mario world' to get the result. I just want to be able to search 'super' and still get the result...
I have setup my own search on my games website, it searches keywords that I store in my database under the name 'tags'.
Now... If I store a 'tag' as say pacman, and search 'pacman' it comes up, but if I search 'pacman game' it doesn't find it because I only stored it as 'pacman'. So what I want help with really is setting it so that the search results don't have to be so specific, any one of the search keywords are found under 'tag' in the DB it will show the results...
My code is something like this:
Code: Select all
<?php
$search = mysql_real_escape_string($_GET['search']);
// Performing SQL query
$query = "SELECT * FROM games WHERE tags = '$search' ORDER BY id DESC";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());