$hostname = 'localhost';
$username = 'mmaaaco_ksecor';
$password = 'hamilton';
$dbh = new PDO("mysql:host=$hostname;dbname=mmaaaco_ksecor", $username, $password);
?>
Untitled Document
/*CREATE TABLE IF NOT EXISTS `3304_posts` (
`id` int(5) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`post` text NOT NULL,
`catid` int(5) NOT NULL,
`userid` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ;
CREATE TABLE IF NOT EXISTS `3304_forumcats` (
`catid` int(5) NOT NULL auto_nicrement,
`catname` varchar(255) NOT NULL,
`catdesc` text NOT NULL,
PRIMARY KEY (`catid`)
) */
$search = trim($_POST['query']);
if ($search) {
$sql = $dbh->prepare("select 3304_posts.id,3304_posts.title,3304_forumcats.catid,3304_forumcats.catname from 3304_posts,3304_forumcats where (3304_posts.title like '%$search%' or 3304_posts.post like '%$search%' or 3304_forumcats.catname like '%$search%') and 3304_posts.catid = 3304_forumcats.catid"); //exact
$sql->execute();
$numresults = 0;
while ($row=$sql->fetch()){
$postid = $row[0];
$posttitle = $row[1];
$catid = $row[2];
$cattitle = $row[3];
$message .= 'Read Post '.$posttitle.'
click here to read all posts from '.$cattitle.'
';
$numresults++;
}
if ($numresults == 0){
$match = $dbh->prepare("select id,title from 3304_posts where match(post) against ('$search')");
$match->execute();
while ($matchrow = $match->fetch()){
$postid = $matchrow[0];
$posttitle = $matchrow[1];
$message .= 'Read Post '.$posttitle.'
';
$numresults++;
}
}
echo 'Your search for \''.$search.'\' generated ('.$numresults.') results
';
echo $message;
}
?>