The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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']"; } |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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'])); } 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? |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|