Jump to content


Search form Question


2 replies to this topic

#1 markc1822

    Young Padawan

  • Members
  • Pip
  • 33 posts
  • Gender:Male
  • Location:New York

Posted 20 June 2009 - 04:40 PM

Hi. How are you guys, I am having a little problem with a search form i created.

I create a search form using PHP and dreamweaver it works but lets say i do a search for "photoshop" it would come up with the results that are in the database.

But, if i search for a combination of words like "photoshop water" even if its in the database it does not show the result. I can only do a search for one word at a time, not a combination of words.

here is what i have in the SQL statments. I think i have to modify something in the statement, but i am not sure where to start.

SELECT *
FROM table1
WHERE tb_title LIKE %colname% OR tb_Description LIKE %desc% OR tb_Category LIKE %cate% OR tb_author LIKE %auth% OR tb_subCat LIKE %subcat%
ORDER BY table1.id ASC

Thanks any help is appreciated

Mark

#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 21 June 2009 - 04:38 AM

Hi!

Well, I guess you'll have to use more OR's in your SQL statement.
The easiest to do would probably be to create the statement dynamically

$searchString = "photoshop water";

$searchTerms = explode(" ",$searchString);
$sql = "select * from table1 where ";
for($i=0;$i<sizeof($searchTerms);$i++)
{
	$sql .= "title LIKE " . $term . " OR ";
	$sql .= "description LIKE ". $term . " OR ";
	$sql .= "author LIKE " . $term;
	if($i<(sizeof($searchTerms) - 1))
	{
		$sql .= " OR ";
	}
}

Something like that would do I guess

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 June 2009 - 02:24 PM

http://dev.mysql.com...ext-search.html





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users