Jump to content

Most Popular Words List: Help?


Pipes

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 */
          $unique_words[$word]++;                     
        }
       
    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;";
   }
         
         
         
         
      }}}}?>[/code]

sorry about the rubbish strange marks as tabs, don't know how to get rid of them.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.