Sentence based search

Search for [WORD] in [CATEGORY]

How would I go about extracting the CATEGORY and WORD from the search query? (above is an example search query)

Not sure how we are supposed to help without seeing the DB schema, or knowing how the searchable phrases/pages/whatever is being stored

Something like this might work.

<?php
$host = "localhost";
//MySQL Database user name.	
$login = "";
//Password for MySQL.
$dbpass = "";
//MySQL Database name.
$dbname = "";
//Establish a connection
$pdo = new PDO("mysql:host=localhost;dbname=$dbname", "$login", "$dbpass");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//Set field and table name to variable		
$CATEGORY = "category";
$TABLE = "tablename";
//Set GET or POST string to variable
//example
$search = "me you";	
//explode search into words array
$words = explode(" ",trim($search));

if(!empty($search)):	
	
	$params = array();
	$presql = array();
	foreach($words as $word):
		$params[] = '%' . $word . '%';
		$presql[] = $CATEGORY . " like ?";
	endforeach;
	
	try {
		//example with extra fields id and date plus the $CATEGORY						
		$sql = "SELECT id, date, " . $CATEGORY . " FROM " . $TABLE . " WHERE ";
		$sql .= implode(" OR ",$presql);		
		$query = $pdo->prepare($sql);
	    $query->execute($params);
		while($row = $query->fetch(PDO::FETCH_ASSOC)){
			echo "<pre>";
			print_r($row);
			echo "</pre>";
		}
	
	} catch(PDOException $e) {
	  echo 'Error: ' . $e->getMessage();
	}
endif;
?>