![]() |
How to make search functions?
I currently use MYSQL queries for searching data. How can I create a function which gets the closest data relative to the search term?
|
Hope you don't mind a bit of reading. Check this out: http://dev.mysql.com/doc/refman/5.1/...xt-search.html
|
FULLTEXT is not supported in INNODB and foreign keys are not supported in MYISAM. :(
|
PHP Code:
|
Did you read my post above?
|
You can't use %$keyword% ?
|
Quote:
|
And what does that mean?
Can't you just say yes or no? >.< Can you or can you not use %$search% ? |
I can use the sprintf.
|
So use it then? :P And use %$search%
|
Quote:
|
What? Wildhoney is not gonna come with something better than my suggestion? :O W000t?!
This is my lucky day.. :D |
Haha. No, no, you seem to have gone about it the right way for what he wants :) !
|
Haha, thanks :)
btw, Haris.. % is a like.. a universal mark, that basicly means "anything". So you search for anything-$searchword-anything. So if you search for ape, you would get the results ape apes tape rape mapex etc.. That's why they are good ;) Also if you search a database, the database "post" would be a string, so you if you don't use the %, you have to search for the whole post to get a result. Let's say you have a news post with this: "Once upon a time there was an ape..." If you don't use %, and search for ape, you don't get anything, cuz you have to search for "Once upon a time there was an ape" to a result. IF you use, you would get the result "ape" and the newspost "once upon a time there was an ape" :) |
To to tie things up a little bit, here's some more information that you might like to know (or might at least entertain reading my post for). The percent symbol (
%) in this case is a wildcard character meaning essentially 'zero or more characters'. To build on the above posts, searching for '%ape%' would match results such as ape, aperitif, tape, psychotherapeutic to name a few. This can be a good feature or bad, depending on the circumstances. Generally people know the word that they want to search for and in this case it would be better to only bring back records with the discrete word ape, rather than records with words containing the letters ape in them. Achieving this won't be covered in this post, but instead I'll move on to what I originally wanted to mention.As well as the percent wildcard, you can also use an underscore ( _) which is another wildcard but behaves differently. Like the percent, it matches any character but this time it will match one, and only one character, rather than 'zero or more'. To give an example, using '_ape' would match records; cape, tape but not lapel, paper, apes, drape, 'blue cape' and so on. |
Yea but salethe, if you search in a database row, the whole content of that row is a string.
Lorem ipsum something blablabla aye sit bla hey! que? If you search for aye, you won't get any result, because there IS something before aye aswell as after. So, you won't get any results from that. That's why you need % on both sides of the search term. |
I'm not here to disagree with your post, just to give a fuller understanding of what can and can't be done. In most cases, using the
% wildcard around your keyword(s) is what you'll want. |
Ahh :P Sorry
|
Thanks for the help!
It worked. Edit: Getting unexpected % error: PHP Code:
|
Hey, you need to encapsulate the percentage signs within your string. Change this:
PHP Code:
PHP Code:
|
| All times are GMT. The time now is 12:43 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0