Im trying to build a search feature to be able to search the forums i have built.
So far, the search by topic works great, but the problem im having is, i have an option to where they can search by Topic only, or Topic and Posts.
With my current code, if it finds the word in posts, its returning the same topic over and over and over .. like if 50 posts in 1 topic contained the word, PHP, it would return the topic 50 times. How can i stop this? Below is my code
// SQL Search DEFINE
if ($search_username != "") {$ssql .=" and a.username like '$search_username'";}
if ($search_replys == "Regular Topic") {$ssql .=" and a.replys < 50";}
if ($search_replys == "Hot Topic") {$ssql .=" and a.replys > 50";}
if ($forum != "0") {$ssql .=" and a.forum_id = '$forum'";}
/////////////// POST CODE THAT IS RETURNING TOO MANY ROWS /////////////////
if ($search_method == "Topic title and posts") {
$psql .="LEFT JOIN shocc_posts d ON a.topic_id = d.topic_id
AND d.post LIKE '%$search_words%'";
}
The above code defines my search terms for SQL
This below code is my main query
##################### MAIN SEARCH QUERY ########################
$sql = mysql_query("SELECT a.topic, a.topic_id, a.forum_id, a.views, a.replys, a.username,a.last_post,a.last_post_user,
c.active_id
FROM shocc_topics a
LEFT JOIN shocc_active c on a.username = c.username
$psql
WHERE a.topic LIKE '%$search_words%'
$ssql
" . $PaginateIt->GetSqlLimit()) or die(mysql_error());
if(mysql_num_rows($sql) <> 0) {
while($row = mysql_fetch_assoc($sql)) {
$results[] = $row;
}
}
I need some help on how i can get the query to return only 1 topic no matter how many posts contain the keyword, instead of listing the topic 50 times if 50 posts inside the topic had the word.
Thanks