Re: counting number of instances of a word

From: Date: Fri, 13 Oct 2000 08:38:20 +0000
Subject: Re: counting number of instances of a word
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19853@lists.php.net to get a copy of this message
Awesome! :) Thanks so much Rick - Best Regards, ian ----- Original Message ----- From: <php3@developersdesk.com> To: Ian Gan <woktoc@pd.jaring.my>; <php-general@lists.php.net> Sent: Thursday, October 12, 2000 9:24 AM Subject: Re: [PHP] counting number of instances of a word 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 -- 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

« previous php.general (#19853) next »