Search with multiple keywords

Hi everyone,

I have a search feature that allows users to search by keyword or other parameters (drop down menus). I would like them to be able to search for keywords, plural. According to other answers, I need to use the explode/implode function, but I’m not quite sure when and where to implement it.

If possible, I would also like there to be no glitch if the user decides to use commas…but getting multiple keywords is definitely first priority.

The second to last “if” statement is for the keywords in question.

Any help would be invaluable. Thank you in advance!

	$select = 'SELECT DISTINCT, joke.joketext, joke.jokedate, 
	   AS author_id, AS author_name, 
	            jokecategory.jokeid AS cat_jokeid, jokecategory.categoryid AS joke_catid, 
	   AS cat_id, as cat_name, 
	            joketheme.jokeid AS theme_jokeid, joketheme.themeid AS joke_themeid,
	            AS theme_id, AS theme_name,
	            jokegeofocus.jokeid AS geofocus_jokeid, jokegeofocus.geofocusid AS joke_geofocusid,
	   AS geofocus_id, AS geofocus_name';
	$from   = ' FROM joke
	            inner join author on (joke.authorid =
	            inner join jokecategory on ( = jokecategory.jokeid)
	            inner join category on (jokecategory.categoryid =
	            inner join joketheme on ( = joketheme.jokeid)
	            inner join theme on (joketheme.themeid =
	            inner join jokegeofocus on ( = jokegeofocus.jokeid)
	            inner join geofocus on (jokegeofocus.geofocusid ='; 
	$first_where = ' where ';
	$where = '';
	$in = ' ORDER BY jokedate DESC';

	if (is_numeric($_POST['aid']))
	{   // An author is selected
	    $where.= $first_where.' authorid='.$_POST['aid'];
	    $first_where = ' and ';

	if (is_numeric($_POST['cid']))
	{   // A category is selected
	    $where.= $first_where.' categoryid='.$_POST['cid'];
	    $first_where = ' and ';

	if (is_numeric($_POST['tid']))
	{   // A theme is selected
	    $where.= $first_where.' themeid='.$_POST['tid'];
	    $first_where = ' and ';

	if (is_numeric($_POST['gfid']))
	{   // A region is selected
	    $where.= $first_where.' geofocusid='.$_POST['gfid'];
	    $first_where = ' and ';

	if (isset($_POST['searchtext']) and $_POST['searchtext'] != '')
	{   // Some search text was specified
	    $where.= $first_where.' keywords LIKE "%'.(mysql_real_escape_string($_POST['searchtext'], $dbcnx)).'%"';

	if($where == '')
	{   // prevents returning the whole database, if form is empty
	    $where = ' limit 20';

You can use implode() to join together your array of keywords into a string to be included in the IN list of your WHERE clause of your sql query.