vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   average words per post (https://vborg.vbsupport.ru/showthread.php?t=30485)

dirgotronix 10-16-2001 12:42 AM

I'd like to have a feature in people's profiles that show the average words per post for that user. Our forums top posters pride themselves in long, meaningful posts, yet we still have people who have yet to post more than a sentance per post. Is there a way one could code in an averageing system that counts the words per post and display that in their profile? The math is easy enough, it's just finding out how many words are in each post that comes as a challenge to me.

Anyone want to help out here? It would be greatly appretiated!

amykhar 10-16-2001 01:48 AM

You might look at this function:

http://www.php.net/manual/en/function.strtok.php

This would help you get the count of the number of words in the message field.

Then, you would need a new field in your database for total number of words posted.

The problem is, users who already have a lot of posts aren't going to have accurate averages unless you create two new fields in the database. One for total words, one for number of posts made since the hack was installed.

Hope that helps you get started.

Amy

dirgotronix 10-16-2001 05:56 AM

Well, my idea was this:

Find some way of taking a users post count, and then going in the post database and for userid=$userid tossing the posts into an array, and then for each post find the wordcount, += it to a var, and then divide by total posts.

I'm not sure how intensive that would be on the database, probably equal to or worse than a search is.

It would be ideal I suppose if it automatically added a field to post for each post, but that would require far more hacking, and scripting something for their previous posts.

dirgotronix 10-16-2001 06:31 AM

Here's the quick script I wrote up, works pretty well from what I can tell, although it is somewhat slow for users with high post counts (although my server is only a P200, it's slow in its old age)

PHP Code:

<?
require("config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);

$result = mysql_query("SELECT pagetext FROM post WHERE userid = $userid ORDER BY dateline ASC");
$number = mysql_num_rows($result);
$i = "0";
$totalcount = "0";
    while($number > $i) {
        $results = mysql_fetch_row($result);
        $string = $results[0];

        $tok = strtok($string," ");
        $count = "0";
        while(!($tok === FALSE)){
            //echo "Word=$tok<br>";
            $count ++;
            $totalcount ++;
            $tok = strtok(" ");

        }
    //echo $i . " " . $count . "<br>";
    $i++;
    }
$average = $totalcount / $number;
$average = number_format($average,3);
echo "Userid $userid has $average Words per post.";
mysql_close($db);
?>


cgwillis 10-23-2002 04:00 PM

Where do you put this code? I'm really interested in implementing this into my board. I wanted to add this to the postbit under the number of posts for the user. Would that be to server intensive?


All times are GMT. The time now is 07:27 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00991 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete