Re: counting number of instances of a word

From: Date: Thu, 12 Oct 2000 16:24:41 +0000
Subject: Re: counting number of instances of a word
Groups: php.general 
Request: Send a blank email to php-general+get-19820@lists.php.net to get a copy of this message
Addressed to: "Ian Gan" <woktoc@pd.jaring.my> php-general@lists.php.net ** Reply to note from "Ian Gan" <woktoc@pd.jaring.my> Thu, 12 Oct 2000 21:04:04 -0700 > > Hi List, i'm trying to get the count of words in a database via a php > search form - for example, i want to know the word(s) that was most > inputed into a database during the day - the query should show me e.g. > top word: fish 450 instances. > > How? Thanks, ian I would probably do something like: $Result = mysql_Query( "SELECT TextField " . "FROM Table " . "WHERE InsertDate = NOW(); while( list( $Text ) = mysql_fetch_row( $Result )) { $Words = explode( ' ', $Text ); while( list( , $Word ) = each( $Words )) { $WordCount[ $Word ] ++; } } $WordCount now contains a list of each different word in the days text, along with the number of times it appears. To find the single most used word, just walk this array and return the highest count value. You might want to do things like downshift all the words before you count them, unless you want Fish and fish to be two different words. Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#19820) next »