Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 02-01-2012, 11:53 AM
aebstract aebstract is offline
 
Join Date: Nov 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default help writing simple plugin

Essentially I just want to do this:

Code:
$result = mysql_query("SELECT COUNT userid FROM userban WHERE adminid = '1'") or die(mysql_error());
while($r=mysql_fetch_array($result)) {
$var = "$r['userid']";
}
and be able to use the variable $var in my template where needed. I'm lost at how I'm suppose to do it since I don't understand hooks that much and am unsure how to code geared for a plugin.
Reply With Quote
  #2  
Old 02-01-2012, 01:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What you'd want to do is register the variable to your template. If the template is being rendered somewhere else, then you want to use "preRegister", like this:

Code:
vB_Template::preRegister('templatename', array('var' => $var));

then in the template you'd put {vb:raw var} wher eyou want it to appear.

There's another issue with what you posted because you might have more than one value returned from your query.

As for which hook location to use, that depends on which template you want to display the data in and where it's rendered.
Reply With Quote
  #3  
Old 02-01-2012, 02:02 PM
aebstract aebstract is offline
 
Join Date: Nov 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay I have this code:
Code:
$result = mysql_query("SELECT COUNT(userid) FROM userban WHERE adminid = '1'") or die(mysql_error());
while($r=mysql_fetch_array($result)) {

vB_Template::preRegister('header', array('bancount' => $r['userid']));

}
I place it in my template like:

Code:
{vb:raw bancount}

Product: vbulletin
Hook Location: global_start



It's not displaying a number or any error on the page at all. I was trying global_start as per your suggestion but is there some sort of method I need to be using to try and find the correct hook location or is this a problem with how the code is written?
Reply With Quote
  #4  
Old 02-01-2012, 02:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm thinking maybe you need to use $r['COUNT(userid)'] to access the results.

As for the hook, when you get it working you might want to find a hook location where your code will only be executed when you're going to display it (global start will be executed on every page). To do that you really need to look at the code, but some people seem to do OK by looking at the list of hook names and guessing or using trial and error. Of course you can ask here as well.
Reply With Quote
  #5  
Old 02-01-2012, 02:23 PM
aebstract aebstract is offline
 
Join Date: Nov 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awesome, adding count in the variable fixed it. I set my hook to parse_templates because an avatar plugin I am using had the same hook and it seems to work. Thanks for your help.
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 02:17 AM.


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.03833 seconds
  • Memory Usage 2,189KB
  • Queries Executed 13 (?)
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
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete