Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-03-2005, 10:05 AM
roundhost roundhost is offline
 
Join Date: Jul 2004
Location: UK
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query users posts for the month...

Hi all,

Basically i plan to query all the users posts for the month by using php to work out the date, and querying how many posts each user has made that month to make a list of the top 10 (exluding admins).

I can do this, but i'm thinking about server load.Going through every single user is quite a task, would it be best to be done on a cron than everytime the page is visited?

RoundHost
Reply With Quote
  #2  
Old 01-03-2005, 10:44 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[sql]
SELECT
userid,
username,
COUNT(*) AS totalposts
FROM
post
WHERE
DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= dateline
GROUP BY
userid
ORDER BY
totalposts DESC
LIMIT
10
[/sql]

That'll do the trick, we're assuming there are 30 days in a month though. Just set it to run at the last day of every month and your users won't know otherwise. If you want it to be completely accurate then I can look that up for you too
Reply With Quote
  #3  
Old 01-03-2005, 11:06 AM
roundhost roundhost is offline
 
Join Date: Jul 2004
Location: UK
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks
Reply With Quote
  #4  
Old 01-03-2005, 01:37 PM
roundhost roundhost is offline
 
Join Date: Jul 2004
Location: UK
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It sortof works :S

Basically, im echoing the results out in a table with the following code:

PHP Code:
echo "<table><tr><td>Username</td><td>Posts</td></tr>";
$result $DB_site->query("SELECT 
        userid,
        username, 
        COUNT(*) AS totalposts 
FROM 
        post
WHERE 
        DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= dateline
GROUP BY 
        userid
ORDER BY
        totalposts DESC
LIMIT 
        10"
);

$row $DB_site->fetch_array($result);

while (
$row mysql_fetch_array($result)) {
echo 
"<tr><td><a href=\"http://www.youngcoders.com/member$row[userid].html\">$row[username]</td><td>$row[totalposts]</td></tr>";
}
echo 
"</table>"
This is not the final code, its just be testing to see if it works...

Anyway, the results i get, are not the top 10 posters in the last week, they are the top 10 posters ever, and my only super mod, doesnt appear in the results, yet i do, even though im a admin :S

I do not see how that could have happened...
Reply With Quote
  #5  
Old 01-03-2005, 01:55 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

take a look at the post below...
Reply With Quote
  #6  
Old 01-03-2005, 04:35 PM
roundhost roundhost is offline
 
Join Date: Jul 2004
Location: UK
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rake
try this:

$cut = 60*60*24*30;
$cut = time() - $cut;

$a = $DB_site->query("SELECT COUNT(*) as count,userid,username
FROM post
WHERE dateline > $cut
GROUP BY userid
ORDER BY count DESC");
while($user = $DB_site->fetch_array($a))
{
if(in_array($user['usergroupid'],array(6,7))
{
continue;
}

.....
}
That doesnt seem to work at all

Thanks for the help though
Reply With Quote
  #7  
Old 01-03-2005, 04:44 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

tiny error. but i just tried it and it works... take a look at the attached file.
Attached Files
File Type: php test.php (898 Bytes, 12 views)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:40 PM.


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.05349 seconds
  • Memory Usage 2,243KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (1)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete