try something like this (not tested): <? $getme = "the big tree"; $getme_arr = explode(" ", $getme); $num = count($getme_arr);
$sql = "SELECT * FROM `hyperlinks` WHERE 1"; for ($i = 0; $i < $num; $i++) if (strlen($getme_arr[$i]) > 0) $sql .= " AND `keywords` LIKE '%".$getme_arr[$i]."%'"; $sql .= " ORDER BY `id` ASC LIMIT 0, 30"; ?> -----Original Message----- From: Philip J. Newman [mailto:[EMAIL PROTECTED]] Sent: Friday, February 15, 2002 11:27 AM To: David Robley Cc: David Robley; [EMAIL PROTECTED]; Gareth Hawken Subject: Re: [PHP] searching key words from a database field the problem is there isn't any code yet and yes what you said is corrent if text input is: the big tree would like $string1 = the would like $string2 = big would like $string3 = tree and so on and so on for all the key words entered. Each key word needs to have its own string alocated. Any suggestions. ps: nice to see another kiwi in here. ----- Original Message ----- From: "David Robley" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, February 15, 2002 1:19 PM Subject: Re: [PHP] searching key words from a database field > In article <000801c1b5b0$ee66f180$0401a8c0@philip>, > [EMAIL PROTECTED] says... > > This works for the loop. now spliting up the words. now it searchs for > > just one word in the loop > > > > any suggestions on this > > > > > > ----- Original Message ----- > > From: "Jason Wong" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Thursday, February 14, 2002 9:51 PM > > Subject: Re: [PHP] searching key words from a database field > > > > > > > On Thursday 14 February 2002 16:38, Philip J. Newman wrote: > > > > I'm trying to make a search engine for my database of links. I have > > been > > > > using the following. > > > > > > > > SELECT * FROM `hyperlinks` WHERE 1 AND `keywords` LIKE '%$getme%' ORDER > > BY > > > > `id` ASC LIMIT 0, 30 > > > > > > > > if $getme = big trees > > > > > > > > then it would only search for key words that are there same "big trees" > > not > > > > for " big and trees" > > > > > > > > > Split up your keywords. Loop through each one to construct something like: > > > > > > SELECT * FROM `hyperlinks` WHERE 1 > > > AND `keywords` LIKE '%big%' > > > AND `keywords` LIKE '%trees%' > > > ORDER BY `id` ASC LIMIT 0, 30 > > > > > > > > > This will only match when ALL the specified keywords are present. To match > > on > > > any one of the keywords construct something like: > > > > > > > > > SELECT * FROM `hyperlinks` > > > WHERE `keywords` LIKE '%big%' > > > OR `keywords` LIKE '%trees%' > > > ORDER BY `id` ASC LIMIT 0, 30 > > > > > > > > > -- > > > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > I don't quite understand what you are asking here? You are using explode > or something to break the input string into separate words, and then > using the list of words to build your query? > > Perhaps showing your problem code might be useful. > > -- > David Robley > Temporary Kiwi! > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php