vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Post count by date range (https://vborg.vbsupport.ru/showthread.php?t=308452)

DRJ 02-16-2014 07:25 PM

Post count by date range
 
I am having trouble working with the dateline field. What I am trying to do is get the top post counts for 2013. But this code will return results but is not restricting to posts in the date range and just gives all the posts.

PHP Code:


// get top 10 posters overall
$poststats="<table border=\"0\">";
$result $db->query("SELECT p.userid , p.username , u.posts
FROM vb_post AS p, vb_thread AS t, vb_forum As f, vb_user As u
WHERE p.threadid = t.threadid
AND t.forumid = f.forumid
AND p.userid = u.userid
AND p.dateline >= UNIX_TIMESTAMP('2013-01-01 00:00:00')
AND p.dateline < UNIX_TIMESTAMP('2014-01-01 00:00:00')
GROUP By p.userid
ORDER BY u.posts DESC
LIMIT 0 , 10"
);
While (
$getstats_posters $db->fetch_array($result))
{
$poststats.=$getstats_posters['username']." - ".$getstats_posters['posts']."<br>";
}
$poststats.="</table>"

echo 
$poststats


kh99 02-16-2014 07:42 PM

It's displaying the count of all posts because you're displaying the 'posts' column from the user table. I think you want to add something like
Code:

COUNT(*) AS yearly_posts
to the select part. Also to be honest I'm not sure what records you get when you select from multiple tables like that - it may not be what you want (or maybe it is, I don't know).

DRJ 02-16-2014 07:48 PM

Gotcha, this worked.

PHP Code:

COUNT(u.posts) AS total 

Thanks :)

kh99 02-16-2014 07:50 PM

Edit - yeah, I just realized it should have been COUNT.


All times are GMT. The time now is 11:03 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.01018 seconds
  • Memory Usage 1,720KB
  • 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_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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