Help - Search - Members - Calendar
Full Version: A Search Form.
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Mathew_Edison
Hey everybody

As you might have noticed I'm new to these forums. Anyways even though I just joined up I already have a question for you people blink.gif . I am currently working on a project to create my own blog and it was coming along quite well until I started the search script. Basically I want to make a search form which will query the database called "post" and the tables title, description and content and then take those results and display them on a page (search.php) This is a completely custom script and I'm writing it from scrap, if there is any more information you need please ask. Even a hint on which functions to use best would be highly appreciated! cool.gif

Thanks in advanced
- Mathew
Alex
SQL
SELECT `col1`,`col2`,`col3` FROM `tbl` WHERE `col4` LIKE "%term%" LIMIT 0, 10


That will find all rows where col4 contains the string "term".

http://dev.mysql.com/doc/refman/5.0/en/str...l#operator_like
Ed
You can also use fulltext matching:
http://devzone.zend.com/node/view/id/1304

You can then order the results by relevance and it's a lot more efficient. The caveat is that there are a number of stop words and if a word appears in too many results it tends to be ignored.

LIKE will work fine with small row sets but a large rowset should take advantage of fulltext searching.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.