john i: php/mysql “user inputed.. search field” HELP???
For the life of me I can not find any help(tutorial) or script.. on how to create a working “user-inputed” search field that would search the working website and a Mysql database. I’m trying to build a “Real Estate” website and incorporate a search function that would be able to search through the listings that I would add to the database. I’ve spent the last two days looking at everything I could find on the web but, I got nothing that seems to work.. If anyone knows what I’m attempting to do and could offer some help.. I’ll take it.
Thanks, John.
Answers and Views:
Answer by james_007_400101
i would suggest implementing lucene its an open source project, you can search any possible thing with it using your database or web. We had implemented it successfully to search for books in our database. Its pretty fast give it a try.
I would like to suggest you simply integrate google search, since that would free up resources on your own server. See: https://support.google.com/adsense/bin/answer.py?hl=en&answer=9879&topic=1705820&rd=2
But let me give you a very basic search function, using PHP/ MySQL
—–StartCode—–
if ((isset($ _POST[‘Search_String’])) && (preg_match(“/^[æøåÆØÅws]{3,24}$ /D”, $ _POST[‘usertext’]))) {
$ Search_String = $ _POST[‘usertext’];
} else { echo ‘Invalid Input’; exit(); }
$ Select_Content = mysql_query(“SELECT * FROM Content_Table WHERE TYPE = ‘C'”, $ Connection);
while ($ Get_Content = mysql_fetch_array($ Select_Content, MYSQL_ASSOC)) {
if (preg_match(“/” . $ Search_String . “/i”, $ Get_Content[‘CText’])) {
echo ‘
Match:’ . $ Get_Content[‘PostTitle’] . ‘
‘;
}
—–CodeEnd—–
The above will only provide absolute basic search functionality. Creating a working site-search can take anywhere between hours to months of development, depending on the complexity. Regular expressions plays a huge role, some search engines even allow the users to use regular expressions in their search strings.
It should however be easy to extend this to cut, and emphasize any matching text, say 20 characters in each direction from the match. Or whatever you want, php has some build-in functions to deal with this.
Leave a Reply