Jump to content

Help making a better search


Jaguar

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.