Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2010, 07:02 AM
bartek24m bartek24m is offline
 
Join Date: Nov 2005
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Count users threads from specific forum ID's

I need insert in member profile page (memberinfo_block_statistics)
MYSQL query (count threads from specific forums ID)



What query i should use in hook area ?
I search forum with similar problem but i only found this::

Code:
SELECT t.forumid = 1 AND t.forumid = 2 AND t.forumid = 3
FROM thread AS t
WHERE t.postuserid = X
Is it correct? What should be a right location for this hook?
What should i repleace X with to get stats for every single user ?


edit: i found also something like this:

PHP Code:
if (is_array($vbulletin->forumcache))
{
    foreach (
$vbulletin->forumcache AS $forum)
    {
        
$totalthreads += $forum['threadcount'];
        if (
$forum['forumid'] == xx$forumthreadcount $forum['threadcount'];
    }

i need copy it somewhere in member.php and place $forumthreadcount in memberinfo_block_statistics template
It does not work

--------------- Added [DATE]1263885685[/DATE] at [TIME]1263885685[/TIME] ---------------

anyone ?
Reply With Quote
  #2  
Old 02-11-2010, 10:38 AM
bartek24m bartek24m is offline
 
Join Date: Nov 2005
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bump !
please reply
Reply With Quote
  #3  
Old 02-11-2010, 12:57 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think something like this works for the query:

Code:
SELECT COUNT(*) AS count FROM thread WHERE postuserid = id AND forumid IN(1, 2)
So I guess you'd want something like:

Code:
$count = $vbulletin->db->query_first("SELECT COUNT(*) AS count
                                                      FROM ".TABLE_PREFIX."thread 
                                                      WHERE postuserid = $vbulletin->userinfo[userid] AND
                                                           forumid IN(1, 2, 3)");
And the result would be in $count['count'].

Where to put it is another question, it looks like the HTML for those blocks is generated in member.php around line 474, and there's a member_build_blocks_start hook right before that, so maybe that's a good place.
Reply With Quote
  #4  
Old 02-11-2010, 01:49 PM
bartek24m bartek24m is offline
 
Join Date: Nov 2005
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for reply mate !

i think that someting else is wrong in $vbulletin->userinfo[userid]
after create new plugin in member profile i can see this error

Code:
Database error in vBulletin 3.7.4:

Invalid SQL:
SELECT COUNT(*) AS count FROM thread WHERE postuserid = Array[userid] AND forumid IN(1, 2, 3);

MySQL Error   : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[userid] AND forumid IN(1, 2, 3)' at line 2
Error Number  : 1064
Reply With Quote
  #5  
Old 02-11-2010, 01:55 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh yeah, sorry, try

Code:
$count = $vbulletin->db->query_first("SELECT COUNT(*) AS count
                              FROM ".TABLE_PREFIX."thread 
                                WHERE postuserid = ".
                                    $vbulletin->userinfo['userid']."
                                    AND forumid IN(1, 2, 3)");
Reply With Quote
  #6  
Old 02-11-2010, 02:38 PM
bartek24m bartek24m is offline
 
Join Date: Nov 2005
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah that's better !

now when i try to add in template MEMBERINFO

Code:
$count['count']
i can't save template i see this error


Code:
The following error occurred when attempting to evaluate this template:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sportforum/domains/sportforum.pl/public_html/includes/adminfunctions_template.php(3772) : eval()'d code on line 8

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
maybe i should use $count[count] insted of $count['count'] ?

or maybe in hook area
insed of:
Quote:
$count = $vbulletin->db->query_first("SELECT COUNT(*) AS count
FROM ".TABLE_PREFIX."thread
WHERE postuserid = ".
$vbulletin->userinfo['userid']."
AND forumid IN(164, 165, 166)");
use

Quote:
ob_start();

$count = $vbulletin->db->query_first("SELECT COUNT(*) AS count
FROM ".TABLE_PREFIX."thread
WHERE postuserid = ".
$vbulletin->userinfo['userid']."
AND forumid IN(164, 165, 166)");


$count = ob_get_contents();
ob_end_clean();
and then in template paste $count
Reply With Quote
  #7  
Old 02-11-2010, 02:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, obviously I didn't try any of this and to be honest I keep forgetting what works in templates. Try $count[count], it should be the same (you might also want to use some variable name other than 'count', it's kind of a common name). There's probably some "right" way to do this without creating a new variable.

I don't think you need to do anything like using ob_start/end. You may need to be using a global, however (I already forgot what the code looked like). I think this may be what template hooks are for, so you don't have to worry about variable name conflicts and globals. Maybe someone who knows more will enlighten us

ETA: Meanwhile, maybe try something like:

Code:
$vbulletin->userinfo['memberinfo_threadcount'] = $count['count'];
in the plugin, then use

Code:
$bbuserinfo[memberinfo_threadcount]
in the template.
Reply With Quote
  #8  
Old 02-11-2010, 06:29 PM
bartek24m bartek24m is offline
 
Join Date: Nov 2005
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i think we're so close but again something is wrong it show always 0

in nut shell what i've done:
name: samle_test
location: member_build_blocks_start
code:
Code:
$count = $vbulletin->db->query_first("SELECT COUNT(*) AS count
                              FROM ".TABLE_PREFIX."thread 
                                WHERE postuserid = ".
                                    $vbulletin->userinfo['userid']."
                                    AND forumid IN(164, 165, 166)");
$vbulletin->userinfo['memberinfo_threadcount'] = $count['count'];
in template: memberinfo_block_statistics

Code:
<li><span class="shade">Płatne Artykuły:</span> $bbuserinfo[memberinfo_threadcount]</li>

And in member profile i can see

Płatne Artykuły: 0

It shoud be 386 not 0

DEMO: http://www.sportforum.pl/members/marcin-hejnowicz.html (Go To Statistic)
Reply With Quote
  #9  
Old 02-11-2010, 06:48 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I guess that means the $bbuserinfo didn't work like I'd guessed. Try this instead: use $template_hook[profile_stats_threadcount] in both places instead of $vbulletin->userinfo['memberinfo_threadcount'] and $bbuserinfo.. etc. And if that doesn't work, add a

global $template_hook;

line before you set it in the plugin.
Reply With Quote
  #10  
Old 02-11-2010, 07:14 PM
bartek24m bartek24m is offline
 
Join Date: Nov 2005
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I dont understand what's:

Quote:
add a global $template_hook;
line before you set it in the plugin.
but if you mean, it should look like:

Plugin:

Code:
$count = $vbulletin->db->query_first("SELECT COUNT(*) AS count
                              FROM ".TABLE_PREFIX."thread 
                                WHERE postuserid = ".
                                    $vbulletin->userinfo['userid']."
                                    AND forumid IN(164, 165, 166)");
$template_hook; 
$template_hook[profile_stats_threadcount] = $count['count'];
template:
Code:
<li><span class="shade">Płatne Artykuły:</span> $template_hook[profile_stats_threadcount]</li>
It still doesn't work
Reply With Quote
Reply

Thread Tools
Display Modes

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 03:34 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04575 seconds
  • Memory Usage 2,265KB
  • Queries Executed 11 (?)
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
  • (13)bbcode_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete