vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Query to get number of post for a user today? (https://vborg.vbsupport.ru/showthread.php?t=96380)

007 09-16-2005 08:19 AM

Query to get number of post for a user today?
 
I need help with a query please...

I haven't been able to get anything to work with the plug in system, but I have seen similar hacks that use a similar idea.

The query needs to pull the number of posts a user has so far today for display in the posbit. (Not the past 24 hours, just in the current day).

How can I do this? Thanks.

~007

Here's the code that worked on 3.0: (rolling 24 hours, however, but this doesn't work either on 3.5)

PHP Code:

$cutoff=time()-86400
$postcount=$DB_site->query_first("SELECT COUNT(*) AS total FROM post WHERE userid='$userid' AND dateline >= $cutoff"); 

I am trying to put it in postbit_start.

It comes up with "Call to a member function on a non-object" and I'm guessing it's because syntax has changed in 3.5... but I haven't the slightest clue where to begin. Any ideas?

White_Snake 09-16-2005 04:27 PM

well, the syntaxis error i can see is that you're using $DB_site-> and as far as i know that's from vb 3.0.x

so the proper command should be

$vbulletin->db->query_frist, so, making the whole sentence be:

PHP Code:

$cutoff=time()-86400
$postcount=$vbulletin->db->query_first("SELECT COUNT(*) AS total FROM post WHERE userid='$userid' AND dateline >= $cutoff"); 


007 09-16-2005 05:27 PM

Thanks, but I get the following with that:

Fatal error: Call to a member function on a non-object in ...../includes/class_postbit.php(251) : eval()'d code on line 2

:( What should I do?

Boofo 09-16-2005 05:29 PM

Try:

$db->query_first

007 09-16-2005 05:32 PM

Hey, I get the same error with that.. Hmmm..

White_Snake 09-16-2005 05:35 PM

0k, now try this:

PHP Code:

$cutoff=time()-86400
$postcount=$vbulletin->db->query_first("SELECT COUNT(*) AS total FROM post WHERE userid='".vbulletin->userinfo[$userid]."' AND dateline >= $cutoff"); 

if that one doesnt do the trick, try this one:

PHP Code:

$cutoff=time()-86400
$postcount=$vbulletin->db->query_first("SELECT COUNT(*) AS total FROM post WHERE userid='".vbulletin->userinfo['$userid']."' AND dateline >= $cutoff"); 


007 09-16-2005 05:37 PM

Getting closer..

I get this:

Parse error: parse error in ..../includes/class_postbit.php(251) : eval()'d code on line 2

White_Snake 09-16-2005 05:42 PM

none of em worked, hmmmm =/ what else can be the error, well, i think this one of this 2 should work:

PHP Code:

 $cutoff=time()-86400
$postcount=$vbulletin->db->query_first("SELECT COUNT(*) AS total FROM post WHERE userid='".vbulletin->userinfo[$userid]."' AND dateline >=".$cutoff.""); 

or
PHP Code:

 $cutoff=time()-86400
$postcount=$vbulletin->db->query_first("SELECT COUNT(*) AS total FROM post WHERE userid='".vbulletin->userinfo['$userid']."' AND dateline >=".$cutoff.""); 


007 09-16-2005 05:49 PM

Bad news... :(

No go. Thanks for helping though. The COUNT (*) isn't the problem is it?

White_Snake 09-16-2005 05:54 PM

hmmm, well, try the query frist via phpmyadmin without variables or vbulletin commands, something like:
[SQL]
"SELECT COUNT(*) AS total FROM post WHERE userid='1' AND dateline >= 86400 ");
[/SQL]

if it doesnt work, well, maybe you have an sql syntaxis error, that's the only way to know if you're right

007 09-16-2005 05:57 PM

That's what I did to start with, and it worked fine. That's why I think it has something to do with how vb3.5 needs to have queries typed in differently somehow :(

White_Snake 09-16-2005 06:08 PM

hmmm i see, well, the query works, but im not sure how to deal with queries that complex, what i have seen from your original was that you wasnt recalling the userid properly and you wasnt cutting the php time variable from the sql sentance

im not sure what else you can do :S

007 09-16-2005 06:10 PM

Well thanks for trying. :) I appreciate it!

On that note, if anybody else has any ideas, I really would like to get this going if possible. Thanks a lot!

Marco van Herwaarden 09-16-2005 06:37 PM

Put a global $vbulletin before the query.

007 09-16-2005 06:40 PM

Hey MarchoH, thanks, but how would that look. Aren't the queries that WhiteSnake entered above already using the $vbulletin before them?

Nullifi3d 09-16-2005 06:58 PM

White Snake, your codes have several errors. As Boofo said: the correct code would be $db->query_first, but it depends on the hook you're inserting this code into.

The following should work with most hooks:
PHP Code:

$datecut TIMENOW 86400;
$postcount $db->query_first("SELECT COUNT(*) AS total FROM " TABLE_PREFIX "post WHERE userid = '{$vbulletin->userinfo['userid']}' AND dateline >= '$datecut'"); 

Display the count in a template with $postcount[total]

007 09-16-2005 07:08 PM

HotLinkHosting, now I am back to the Fatal Error from before:

Fatal error: Call to a member function on a non-object in ..../includes/class_postbit.php(251) : eval()'d code on line 2

The hook I am using is postbit_display_start.. I have tried it in other postbit hooks with the same problem however.. I think that is the right hook to use though. It makes sense at least according to where it is in the code..

White_Snake 09-16-2005 07:16 PM

Quote:

Originally Posted by 007
HotLinkHosting, now I am back to the Fatal Error from before:

Fatal error: Call to a member function on a non-object in ..../includes/class_postbit.php(251) : eval()'d code on line 2

The hook I am using is postbit_display_start.. I have tried it in other postbit hooks with the same problem however.. I think that is the right hook to use though. It makes sense at least according to where it is in the code..

so well, exaclty which error are you reciving using whit the code i gave you?

well try this now, inspired on Hotlink code:

PHP Code:

$datecut TIMENOW 86400;
$postcount $db->query_first("SELECT COUNT(*) AS total FROM " TABLE_PREFIX "post WHERE userid = '".$vbulletin->userinfo['userid']."' AND dateline >= ".$datecut.""); 


Boofo 09-16-2005 07:20 PM

Shouldn't it be this:

PHP Code:

 global $vbulletin;
$datecut TIMENOW 86400
$postcount $db->query_first("SELECT COUNT(*) AS total FROM " TABLE_PREFIX "post WHERE userid = '".$vbulletin->userinfo['userid']."' AND dateline >= ".$datecut.""); 


White_Snake 09-16-2005 07:22 PM

Quote:

Originally Posted by Boofo
Shouldn't it be this:

PHP Code:

 global $vbulletin;
$datecut TIMENOW 86400
$postcount $db->query_first("SELECT COUNT(*) AS total FROM " TABLE_PREFIX "post WHERE userid = '".$vbulletin->userinfo['userid']."' AND dateline >= ".$datecut.""); 


hmmm i see, so, what's the function of global $vbulletin with the whole query?

007 09-16-2005 07:45 PM

WhiteSnake and Boofo, both of yours both give me this error:

Fatal error: Call to a member function on a non-object in ..../includes/class_postbit.php(251) : eval()'d code on line 3

Marco van Herwaarden 09-16-2005 07:54 PM

PHP Code:

global $vbulletin;
$datecut TIMENOW 86400
$postcount $vbulletin->db->query_first("SELECT COUNT(*) AS total FROM " TABLE_PREFIX "post WHERE userid = ".$vbulletin->userinfo['userid']." AND dateline >= $datecut"); 


007 09-16-2005 08:04 PM

Awesome MarchoH64! That worked! :) Thanks a lot.

White_Snake 09-16-2005 08:09 PM

well, i learned something new today

Marco van Herwaarden 09-16-2005 08:18 PM

Like i said on the previous page, just add the global $vbulletin.

Nullifi3d 09-16-2005 08:38 PM

why does my code work in forumhome_start, but not elsewhere?

Too bad all hooks don't use the same code :(

007 09-16-2005 08:56 PM

Yeah it's confusing. :(


All times are GMT. The time now is 07:43 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.01888 seconds
  • Memory Usage 1,801KB
  • 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
  • (11)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (27)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