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

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'");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.