Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] 2 words search From: jkraai (jkraai <email protected>)
Date: 03/28/99

Valerio Fioretti wrote:
>
> Hello, I have a problem with a query. I'd like to make a search in a
> table inserting 2 or more words in the input form, using the OR.
> Everything works fine with 1 word but with more I obtain result only for
> the LAST inserted one.
>

// Assuming id is a unique key

$words = explode (" ", $search);
$num = COUNT ($words);
WHILE ($n<$num) {
        $queryWhereArray .= "(title like %".$words[$n]."% or text like "..$words[$n].")";
}

$queryWhere = join(" or ",$queryWhereArray);

$query = "select count(id) as k, *
from news
where $queryWhere
group by k
order by id desc"

$result = MYSQL_QUERY($query);

will get you what you're looking for.

This will be very tough on the database if the news table
gets large. You'll need to find a better way.

--jim

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>