Re: [PHP] Creating mySql search feature.....

2002-11-24 Thread Cookra
Thank you Marek






"Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> You first need to separate the words and then build your query:
>
> $words = explode(' ',$S_For);
> $cond='';
> foreach($word as $str) {
> $cond .= " $S_From LIKE '%$str%' AND ";  // replace AND with OR if
> you want ANY word
> }
> // remove trailing AND(last 4 chars) or OR(last 3 chars)
> $cond = substr($cond, 0, strlen($cond) - 4); //  this is for AND
>
> And I hope you check the value of $S_From if it is valid
>
>
> Cookra wrote:
>
> >Hi all,
> >Need a little help here been at this for a while now...
> >
> >I have a database holding a table which in turn holds a collection of
fields
> >I need to search.
> >
> >Ive set up search form that sends the variable $S_For and $S_From, these
> >variables represent the following:
> >
> >$S_For = the search keyword itself
> >$S_From = the column which I need to search
> >
> >Ive created this and it works fine for single words, the problem as you
may
> >of guessed is when I enter a string of words ie:
> >
> >apple - works fine
> >
> >orange - works fine
> >
> >apple orange - doesnt
> >
> >Any help would be ideal
> >
> >-
> >
> >Databse = clientacc
> >Table = hospitality
> >
> >-
> >
> >Everything else works on my site apart from this search
> >feature.. please help!
> >
> >
> >Regards
> >
> >R
> >
> >
> >
> >
> >
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Creating mySql search feature.....

2002-11-24 Thread Marek Kilimajer
You first need to separate the words and then build your query:

$words = explode(' ',$S_For);
$cond='';
foreach($word as $str) {
   $cond .= " $S_From LIKE '%$str%' AND ";  // replace AND with OR if 
you want ANY word
}
// remove trailing AND(last 4 chars) or OR(last 3 chars)
$cond = substr($cond, 0, strlen($cond) - 4); //  this is for AND

And I hope you check the value of $S_From if it is valid


Cookra wrote:

Hi all,
   Need a little help here been at this for a while now...

I have a database holding a table which in turn holds a collection of fields
I need to search.

Ive set up search form that sends the variable $S_For and $S_From, these
variables represent the following:

$S_For = the search keyword itself
$S_From = the column which I need to search

Ive created this and it works fine for single words, the problem as you may
of guessed is when I enter a string of words ie:

apple - works fine

orange - works fine

apple orange - doesnt

Any help would be ideal

-

Databse = clientacc
Table = hospitality

-

Everything else works on my site apart from this search
feature.. please help!


Regards

R



 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Creating mySql search feature.....

2002-11-24 Thread Hatem Ben
Hello,

What you need is :
1- parse your query and make it boolean
"apple orange"  become "apple and orange" and so on

2- then you can generate a MySQL query based on that like this way

---
SELECT id, field1
match (field1) against (' apple orange ') as relevance
FROM hospitality
WHERE
match (field1) against ('apple')>0 AND match (field1) against ('orange')>0
HAVING relevance>0
ORDER BY relevance DESC
---

field1 will be your field(s) you're searching in.

Hope this will help
Hatem


"Cookra" <[EMAIL PROTECTED]> a écrit dans le message de news:
[EMAIL PROTECTED]
> Hi all,
> Need a little help here been at this for a while now...
>
> I have a database holding a table which in turn holds a collection of
fields
> I need to search.
>
> Ive set up search form that sends the variable $S_For and $S_From, these
> variables represent the following:
>
> $S_For = the search keyword itself
> $S_From = the column which I need to search
>
> Ive created this and it works fine for single words, the problem as you
may
> of guessed is when I enter a string of words ie:
>
> apple - works fine
>
> orange - works fine
>
> apple orange - doesnt
>
> Any help would be ideal
>
> -
>
> Databse = clientacc
> Table = hospitality
>
> -
>
> Everything else works on my site apart from this search
> feature.. please help!
>
>
> Regards
>
> R
>
>
>
> --
> 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