Jaguar Posted April 20, 2007 Share Posted April 20, 2007 I have a basic search I made, but it doesn't work very well. In my database I have author, date, title, description, and keywords fields. Right now it works like this, // SEARCH KEYWORDS FIRST $result = mysql_query( "SELECT * FROM table WHERE keywords LIKE '%$search%'" ) or die( mysql_error () ); $total_records = mysql_num_rows( $result ); // SEARCH DESCRIPTION if( $total_records == 0 ) { $result = mysql_query( "SELECT * FROM table WHERE description LIKE '%$search%'" ) or die( mysql_error () ); $total_records = mysql_num_rows( $result ); } // SEARCH TITLE if( $total_records == 0 ) { $result = mysql_query( "SELECT * FROM table WHERE title LIKE '%$search%'" ) or die( mysql_error () ); $total_records = mysql_num_rows( $result ); } It only gets results from keywords, then stops, or description and stops. I want to include results from keywords and description but exclude the duplicate records. I can't figure out how to do it. I'm thinking I have to do something like "WHERE title LIKE "%$search%" AND keywords NOT LIKE "%$search%" then join the results some how. I need to get all the results together before I start printing the data. Can I join results somehow? I know I could just get the results from keywords, print, then description, then print, etc. but that doesn't seem effecient to me and won't work with what I have. Link to comment https://forums.phpfreaks.com/topic/47894-help-making-a-better-search/ Share on other sites More sharing options...
per1os Posted April 20, 2007 Share Posted April 20, 2007 http://en.wikipedia.org/wiki/Full_Text_Search You want your fields to have a full text index, provides for much better searching capabilities. Link to comment https://forums.phpfreaks.com/topic/47894-help-making-a-better-search/#findComment-234048 Share on other sites More sharing options...
utexas_pjm Posted April 20, 2007 Share Posted April 20, 2007 Use DISTINCT. http://www.google.com/search?q=mysql+distinct+keyword. Best, Patrick Link to comment https://forums.phpfreaks.com/topic/47894-help-making-a-better-search/#findComment-234051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.