vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need a little help (https://vborg.vbsupport.ru/showthread.php?t=53489)

MuSuL 05-28-2003 10:34 AM

Need a little help
 
I'm trying to code a little hack to display the top 10 posters for the month. I'm a little stuck on the SQL code. Actually, the dateline is what is the problem

This is the sql statement

SELECT count( * )
as postcount, username, userid
FROM post
where dateline
between startdate
and enddate
GROUP BY userid
ORDER BY postcount DESC
LIMIT 0, 10

It returns no record. I know it's because the date is stored in that millisecond format but I am having problems in finding out how to select it. Can anyone give me a hand?

filburt1 05-28-2003 12:11 PM

[sql]
SELECT COUNT(p.postid) AS postcount, u.username, p.userid FROM post p, user u
WHERE p.dateline > [last month]
AND u.userid = p.userid
GROUP BY u.userid ORDER BY postcount DESC LIMIT 10
[/sql]
...theoretically.

MuSuL 05-28-2003 01:30 PM

I don't see why I have to go into the user table as post has the username and userid fields.

Also from what I've learned, count(*) should execute faster than a count on a field.

Lastly that
WHERE dateline > [last month]
I understand your logic on this but how do I format [last month] so it will select something. The format for vb is in milliseconds that is hard to understand by looking at it.
I would like to do something like
WHERE dateline > 2003-04 AND dateline <= 2003-05
so I can refer to a specific month in the future.

It's the formatting of the date for the WHERE clause that I'm stuck on.

filburt1 05-28-2003 01:38 PM

The username is cached in the post table. In the user table, it's perpetually up to date.

Look up http://us3.php.net/mktime

MuSuL 05-28-2003 01:47 PM

Thanks...will do some more reading with the link you posted :)

MuSuL 05-28-2003 02:16 PM

Ok, I think I got it. This is what I did and it seems to return the proper values.

SELECT count( * ) as posts, username, userid
FROM post
where date_format( from_unixtime( dateline ) , '%Y-%m' ) = '2003-04'
GROUP BY userid
ORDER BY posts DESC LIMIT 10


All times are GMT. The time now is 01:47 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.01383 seconds
  • Memory Usage 1,717KB
  • 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)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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