Re: Help : search for a word and its number
| From: | Hugh Bothwell | Date: | Wed, 01 May 2002 13:47:19 +0000 |
| Subject: | Re: Help : search for a word and its number | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-18926@lists.php.net to get a copy of this message | ||
> If I have records like this
> ID Content
> 1 "John have a red book, and a yellow book. He give a yellow book to
Tina".
> 2 "Luke doesn't have any book at all, he always borrow it from John".
> 3 "John like swimming".
>
> Can I search this records (table) for a word "book" and also number of
"book"
> occurences at every record?
>
> From table above, the result would be
> ID Number
> 1 3
> 2 1
> I use Oracle 8.1.7.
I'm not an Oracle expert - you may be able to do the whole thing in SQL -
but as a first approximation:
SELECT ID, Content FROM MyTable WHERE Content LIKE '%book%'
then for each returned record,
echo $id." ".substr_count($content, "book");