0

Hey everyone. I'm having some trouble returning the correct number of matched results after a search query is issued to my site's search bar.

I was using this, but it returns the wrong number of matches (only for certain queries):

$countofrecs = mysql_query("SELECT count(*) from tablename WHERE title OR description LIKE '%".$searchterm."%' OR catid = '$catid'");

$cnt = mysql_fetch_array($countofrecs);

echo "Your search terms returned '$cnt[0]' results";

Thanks

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by urtrivedi
0

I have written changes in bold letters. You must add some expression against title column you cannot write title or description.

change your query as following.

$countofrecs = mysql_query("SELECT count(*) from tablename
WHERE
title LIKE '%".$searchterm."%'
OR description LIKE '%".$searchterm."%'
OR catid = '$catid'");

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.