Re: boolean search
| From: | jtjohnston | Date: | Tue, 06 Nov 2001 07:48:47 +0000 |
| Subject: | Re: boolean search | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73554@lists.php.net to get a copy of this message | ||
So your code would look like?
$news = mysql_query('select * from news_elsst01 where '.$where.'order by
news_title desc');
When I type "john AND mary", it explodes it into 3 different $words?
Can you explain what $type is?
I'm still learning, and only really half learned Perl, so if you could indulge
me, I'll never know/learn unless I ask:
What does "foreach ($words as $val)" means? ... What kind of operator is "as"?
Thanks,
John
> 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.delete@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