RE: [PHP] boolean search

From: Date: Tue, 06 Nov 2001 06:11:18 +0000
Subject: RE: [PHP] boolean search
Groups: php.general 
Request: Send a blank email to php-general+get-73548@lists.php.net to get a copy of this message
The way I've done this in the past is to do something like: // assume AND/OR coming in in $type // $searchme is another input $where = ""; $words = explode(" ", $searchme); foreach ($words as $val) { if (strlen($where) > 0) $where .= " $type "; $where .= "field like '%$val%'"; } // now tap $where on to your sql statement -----Original Message----- From: jtjohnston [mailto:jtjohnston@courrier.usherb.ca] Sent: Tuesday, November 06, 2001 4:41 PM To: php-general@lists.php.net Subject: [PHP] boolean search Hi, I'm looking for a piece of code that can do a boolean search from an <input type=text name=searchme>. Therefore, if the user types "AND" it will perform boolean <input type=text name=searchme value="john AND mary"> Anything available? John ---------------------------------------------------------------------------- --------------------------------------------- This is what I am doing so far: $lien = mysql_pconnect("localhost","username","password"); mysql_select_db("database",$lien); $news = mysql_query('select * from news_elsst01 where news_title like "%'.$searchenquiry.'%" order by news_title desc'); $mycounter = 0; while ($personne = mysql_fetch_object($news)) { $mycounter++; } echo "\t<font color=blue face=\"arial,helvetica\" size=3><b>Your search found $mycounter entries!</b></font>\n\t<hr>\n\n"; $news = mysql_query('select * from news_elsst01 where news_title like "%'.$searchenquiry.'%" order by news_title desc'); while ($personne = mysql_fetch_object($news)) { echo "<li><a href=\"".$personne->news_filename."\"><font size=3 color=red face=\"arial,helvetica\"><B>".$personne->news_title."</B></font></a> (<font size=1 color=Blue face=\"arial,helvetica\">By: ".$personne->news_credit."</font>)<br><font size=2 color=black face=\"arial,helvetica\">"; //substr($personne->news_intro, 0, 200) // letters $words = explode(" ", $personne->news_intro); //words for ($i = 0; $i <= 40; $i++) { echo "$words[$i] "; } echo " ...</font></a>\n\n"; } -- 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

« previous php.general (#73548) next »