Jump to content


Most Popular Words List: Help?

  • Please log in to reply
No replies to this topic

#1 Pipes

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 October 2006 - 09:37 PM

Hello again gurus. Thanks for your help last time. I managed to fix the problem. Try as I might though, I have been unable to crack this extension to a MySQL/PHP script that queries the database (all fine), and tried to search through all of the returned records and search for the most used words (of more than 3 letters). Every time I try this out, I get no results in the output, but there are no error messages. Can anyone point me in the right direction? It's probably something simple that i'm overlooking but it's driving me mad!

thanks in advance. Andy

<?php function most_used_words_cloud()
  // display most used words

  // set global variable, so we can test later if this is on the page
      $sql = "SELECT quote FROM quotes";
      $result = mysql_query($sql);
             * If we got here, we know that the $result variable
             * contains a resource identifier through which
             * we can loop through the rows returned and 
             * display the row fields
		  $unique_words = array();
  		  while ($record = mysql_fetch_array($result)) 
    		    	   $words = preg_split("/[\W]+/", $record[1]);
    		  	   foreach ($words as $word) {
    		  	   /** weed out words that are fewer than three letters long */
     	  	   	  if (strlen($word) < 3) {continue;}  
 					if (array_key_exists($word, $unique_words)) 
        	  			/** shorthand for increasing value of $word by one if $word exists in $unique_words */
		   			else {
        	  			/** initialize the counter to 1 for this word */
        	  			$unique_words[$word] = 1;
        	  			// converts number of occurrences into big/small font
		  			$num_words = count($unique_words);   
		  			$unique_word_keys = array_keys($unique_words);    
				   			   foreach ($unique_word_keys as $unique_word_value) 
   		  					   $num_occurrences = $unique_words[$unique_word_value];
   		  					   //if ($num_occurrences < 10) continue;
   		  					   $size = 10 + ($num_occurrences / 2);
   	    	  					   echo "<span style=\"font-size: $size\">$unique_word_value</span> &nbsp;";

sorry about the rubbish strange marks as tabs, don't know how to get rid of them.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users