<?
include '../connect.php';
$submit = $_POST['submit'];
if ($submit != '')
  {
//bare minimum...but will work!
$search = $_POST['search'];
$searchlike = '%'.$search.'%';



//the following search generates the number of results 
$getnumsql = $dbh->prepare("select count(*) from 3304_posts,3304_topics where 3304_posts.title like ? or 3304_posts.posttext like ? or 3304_topics.topicname like ?");


$getnumsql->execute(array($searchlike,$searchlike,$searchlike));
$numresults = $getnumsql->fetchColumn();
echo 'Your search for '.$search.' generated ('.$numresults.') results.<br/>'; 




$sql = $dbh->prepare("select 3304_posts.postid,3304_posts.title,3304_posts.posttext,3304_topics.topicid,3304_topics.topicname from 3304_posts,3304_topics where 3304_posts.title like ? or 3304_posts.posttext like ? or 3304_topics.topicname like ?");


$sql->execute(array($searchlike,$searchlike,$searchlike));
while ($row = $sql->fetch())
    {
$id = $row[0];
$title = str_replace($search,'<strong>'.$search.'</strong>',$row[1]);
$posttext = str_replace($search,'<strong>'.$search.'</strong>',$row[2]);
echo $title.'<br/>'.$posttext.'<br/><br/>';
	}
	  
  }
?>

<form action = "search.php" method = "post">
Search:<input type = "text" name = "search"/><br/>
<input type = "submit" name = "submit" value = "Search"/>
</form>
