Re: PHP+MySQL SEARCH

From: Date: Mon, 19 Feb 2001 08:06:31 +0000
Subject: Re: PHP+MySQL SEARCH
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40539@lists.php.net to get a copy of this message
> if ($search_in == "1"){ > $query1 = "SELECT * FROM FISH where ID LIKE '%$search_text%' > OR name LIKE '%$search_text%' OR Category LIKE '%$search_text%' OR Color > LIKE '%$search_text%' OR Size LIKE '%$search_text%'"; > } Looks good the way it is for now. Things you *could* do: 1) Break up your query like this: $query1 = "select * from fish "; $query1 .= " where id like '%$search_text%' "; $query1 .= " or name like '%$search_text%' "; . . . 2) Calculate a "score" for your search: $query1 = "select *, "; $query1 .= " ( id like '%$search_text%' "; $query1 .= " + name like '%$search_text%' "; $query1 .= " + category like '%$search_text%' "; . . . $query1 .= " ) as score "; $query1 .= " where score > 0 "; $query1 .= " order by score desc "; So, here, a record gets a "point" for each match, and we add all the "points" up as a "score" and now you have not only all the matches, but you have a "score" for each to say how *good* the match is. You could even give more "weight" to the name field by using: $query1 .= " + 3*(name like '%$search_text%') "; Here, a "match" in the name field is 3X as important as in the category field. You could also try to build an "advanced search" form where users would pick which fields to search in. -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#40539) next »