/    Sign up×
Community /Pin to ProfileBookmark

Match Against Problem

I have never used the following SQL request so please excuse my inexperience with it.

I am trying to create a search engine that looks through two columns in my database and returns the rows that contain matches.

I have set the columns to ‘Full Text’ and no errors are appearing when I load the page. It is just not getting any results!!

Here is my code:

[code=php]$profilesSQL=”SELECT * FROM profiles WHERE MATCH(name, rel) AGAINST (‘%$query%’) LIMIT 10″;
[/code]

If I type ‘hel’ then I would expect to get the following results:

Hello
My name is Helen
etc…

Any help much appreciated.

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@qrizlyMay 24.2011 — you have to leave the "%" chars out of the query and then it will work:

[code=php]$profilesSQL="SELECT * FROM profiles WHERE MATCH(name, rel) AGAINST ('$query') LIMIT 10"; [/code]

You might want to look here: http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html
Copy linkTweet thisAlerts:
@Benji6996authorMay 25.2011 — Thanks qrizly, I have sorted it by using a different method. I didn't like how 'match against' only matches full words so for instance if I typed 'hel', it wouldn't find 'hello'!

I also had trouble with my options file not accepting the new settings I put in 'ft_min_word_ln' (or whatever it is). After rebuilding the index's and restarting apache I still couldn't get it to work but not a problem now because I have gone down a different (slower) route.

Thanks anyway.
Copy linkTweet thisAlerts:
@papartsMay 27.2011 — [CODE]
$profilesSQL="SELECT * FROM profiles WHERE name like '%$query%' or rel like '%$query%' LIMIT 10";
[/CODE]
×

Success!

Help @Benji6996 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...