homepage Welcome to WebmasterWorld Guest from 54.227.67.210
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Two Problems: % Wildcard & FULL-TEXT Searches
ony results for first column that is searched... & no partial matches
alcheme




msg:1299730
 10:15 pm on Jan 23, 2005 (gmt 0)

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

 

alcheme




msg:1299731
 12:44 am on Jan 24, 2005 (gmt 0)

I feel like such a geek for solving my own questions but I did find something useful.

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved