Jump to content


This topic is now archived and is closed to further replies.


Most Popular Words List: Help?

Recommended Posts

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

[code]<?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.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.