Re: Searching

From: Date: Wed, 19 Jul 2000 18:15:28 +0000
Subject: Re: Searching
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-7328@lists.php.net to get a copy of this message
Ed, No problem man. Happy coding... :) Ryan On Wed, Jul 19, 2000 at 10:40:53AM -0700, Edward Vul wrote: > Hey, that is very cool, I was just on the verge of giving up and just > searching one field! > That is so awesome... > > Thanks a lot, > Ed > > > -----Original Message----- > From: Ryan Adams [mailto:radams@fcs.uga.edu] > Sent: Wednesday, July 19, 2000 10:34 AM > To: Ed Vul > Cc: php-general@lists.php.net > Subject: Re: [PHP] Searching > > > I wrote a function a little while back that will turn a google type search > string in the > form "+this andthis +thistoo -notthis" into a multiple field search query. > It could probably > use a little cleanup, but hey it works. > > function boolean_query ($str, $tablename, $searchfields, $resultfields, > $after_where) { > // ryan adams 6/6/00 > $a_fields = explode (" ", $searchfields); > > $a = explode (" ", $str); > while (list($k, $v) = each ($a)) { > if ($v[0] == "-") { > $a_query[] = "NOT LIKE \"%".substr ($v, 1)."%\""; > } elseif ($v[0] == "+") { > $a_query[] = "LIKE \"%".substr ($v, 1)."%\""; > } else { > // default case > $a_query[] = "LIKE \"%$v%\""; > } > > } > > for ($i=0; $i<@count($a_fields); $i++) { > $naq = ""; > for ($j=0; $j<count($a_query); $j++) { > $naq[]="$a_fields[$i] $a_query[$j]"; > } > $b_query[] = "(".implode (" AND ", $naq).")"; > } > $q = implode (" OR ", $b_query); > > $q1 = "select $resultfields from $tablename where ($q) "; > if ($after_where) $q1 .= $after_where; > > return $q1; > } > > > $searchstr = "this +andthis -notthis +yesthis"; > $query = boolean_query ($searchstr, "mytable", "field1 field2 field3", > "*", > "order by anotherfield"); > > > Hope this helps, > Ryan > > > On Mon, Jul 17, 2000 at 11:03:17AM -0700, Ed Vul wrote: > > I am not quite sure how I should do this: > > I need to make a feature that would search several columns in a table for > > stuff. > > What I'm not sure is, how would I make it work like a normal searchn > (using > > and, or, etc.), are there some kinds of functions in PHP for this? or do > I > > have to parse the search string? I'm not quite sure where I would begin. > > On top of my php incompetence, I don't know sql very well, so that adds to > > my problem. > > Any pointers (no pun intended), in the right direction would help. > > > > Thanks > > Ed > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > ---end quoted text--- ---end quoted text---

« previous php.general (#7328) next »