Forum Moderators: coopster
With regards to this SQL statement.... It works great for multi-word searches but those searches have to be spelled correctly.
I have discovered two FLAWS:
1. It does not allow for partial matches: i.e. 'shane' if the search is spelled 'shan' it will not find it. I cannot figure out how to get the '%' Wildcard into this statement so it will work.
2. It will ony show results for the first column the search word(s) are found in.
For example, I type in 'shane' and I will get all listings for 'shane' only from the 'wname' column. The search query stops at the first column 'wname' in the SQL statement below and ignores that 'shane' is also located in several other columns and records.
-------> Begin Code
<?
include("inc/db.inc.php");
if(isset($_POST['search']) &&!empty($_POST['search'])) {
mysql_connect() or die ("Problem connecting to Database");
$search = trim($_POST['search']);
$sql= mysql_query("SELECT * FROM directory WHERE MATCH (wname,title,keywords,description,city,country,cat
egory,url) AGAINST ('" . $_POST['search'] . "') ", $db);
<------- End Code
Any ideas?
% WILDCARD: These did not work:
$sql= mysql_query("SELECT * FROM directory WHERE MATCH (wname,title,keywords,description,city,country,cat
egory,url) AGAINST ('" . $_POST['%search%'] . "') ", $db);
NOR THESE
('%" . $_POST['search'] . "%')
%('" . $_POST['search'] . "')%
'%'('" . $_POST['search'] . "')'%'
~Shane
I added:
AGAINST ('" . $_POST['search'] . "' IN BOOLEAN MODE)
Now it searches all columns instead of stopping at the first in the FULLTEXT search list.
However, I still need to figure out how to incorporate the % Wildcard into this SQL statement:
$sql= mysql_query("SELECT * FROM directory WHERE MATCH (wname,title,keywords,description,city,country,category,url) AGAINST ('" . $_POST['search'] . "' IN BOOLEAN MODE) ", $db);
Any ideas?
~Shane