Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2009, 11:40 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Creating a simple hit counter?

Hi all i have created a new database called mycounter and then created a plugin like this
Product : VBulletin
Hook Location :Global_Start
Title: Hit Counter
Execution Order : 5
Plugin PHP Code :
PHP Code:
<if condition="$show['member']">
$result mysql_query("SELECT count FROM mycounter"); 
$mycounter mysql_result($result0) + 1
$result mysql_query("UPDATE mycounter SET count = count + 1");
</if> 
i then added this to my desired page:
PHP Code:
<table class="tborder" cellpadding="$stylevar[cellpadding]cellspacing="$stylevar[cellspacing]border="0" width="10%" align="center">
<
td class="tcat"><center>Hit Counter</td>
<
tr align="center"><td font size="+2" color="blue">$mycounter 
</td></tr>
</
table
My problem is that it won't show the count unless i remove the if condition, i'm no coder, but what i am trying to do is just count the number of members who visit the page not guests, can anyone help?
Reply With Quote
  #2  
Old 01-19-2009, 03:27 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You cannot use template conditionals in plugins. You need to use PHP code in plugins.
PHP Code:
if ($show['member'])
{
    
$result $vbulletin->db->query_first("SELECT count FROM mycounter LIMIT 1");
    
$mycounter $result['count'] + 1;
    
$vbulletin->db->query_write("UPDATE mycounter SET count = $mycounter");

Reply With Quote
  #3  
Old 01-19-2009, 05:12 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the code but the counter still doesn't show anything when using the code you supplied, it will only show a figure if i use
PHP Code:
$result mysql_query("SELECT count FROM mycounter"); 
$mycounter =  mysql_result($result0) + 1
$result =  mysql_query("UPDATE mycounter SET count = count + 1"); 
The counter is at the bottom of this page http://www.thecodecage.com/forumz/helpvideos.php
Reply With Quote
  #4  
Old 01-19-2009, 05:23 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if ($vbulletin->userinfo['userid'])
{
    
$result $vbulletin->db->query_first("SELECT count FROM mycounter LIMIT 1");
    
$mycounter $result['count'] + 1;
    
$vbulletin->db->query_write("UPDATE mycounter SET count = $mycounter");

Reply With Quote
  #5  
Old 01-19-2009, 06:19 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, thats it!, seems to work well!

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

The counter is working, but it seems too well, it seems that its counting every members hit on every page. is it possible to just lock it down to my custome page?
Reply With Quote
  #6  
Old 01-20-2009, 10:52 PM
pein87's Avatar
pein87 pein87 is offline
 
Join Date: Sep 2008
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

when you run it in a template use the this but warn you that you must define the script in the top of the custom pages template.

<if condition="THIS_SCRIPT == 'my_custom_page'">
<!-- execute this code -->

<!-- /execute this code -->
</if>

That should work so it only displays it on that page and I`m sure you can pass that definition to your php code so it only respnds to hits on that page and with the conditional above it only displays that info on that page if you add it to lets say the footer no need for a custom template.

I would use

if (THIS_SCRIPT == 'mycustom_page')
{
//start code

//end code
}

I wouldnt use an else unless you really need the option.

Hope it helps you.
Reply With Quote
  #7  
Old 01-21-2009, 03:15 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No need to use any template conditionals. (The HTML is only put in the custom template.) Just change the plugin.
PHP Code:
if (THIS_SCRIPT == 'yourscript' AND $vbulletin->userinfo['userid'])
{
    
$result $vbulletin->db->query_first("SELECT count FROM mycounter LIMIT 1");
    
$mycounter $result['count'] + 1;
    
$vbulletin->db->query_write("UPDATE mycounter SET count = $mycounter");

Reply With Quote
  #8  
Old 01-21-2009, 07:58 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks again, but i couldn't get it to work!, my php script is helpvideos.php and my custom template is helpvids.

Thanks for continuing support for this.

EDIT: As i said i am no coder, i tried helpvideos.php and helpvids in place of your script.
Reply With Quote
  #9  
Old 01-21-2009, 08:17 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

At the top of "helpvideos.php" there should be something like:
PHP Code:
define('THIS_SCRIPT''XXXXXXXX'); 
Put that "XXXXXXXX" in place of "yourscript".
Reply With Quote
  #10  
Old 01-21-2009, 08:31 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dismounted, you definitely know what you're doing! your changes to the code worked, i had the script defined as helpvideos, used that and the counter is showing again, so i have reset it to zero and will post back.....thanks very much!!!!

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

UPDATE: Yep, that seems to work perfect, i logged out and accessed the custom page several times, i was shown the hit counter but no figures, then logged back in, clicked the page and the counter figures were seen and incremented.

1 question, can i use the IF condition you posted in my script around the counter stuff to prevent non members even seeing the counter box?
Reply With Quote
Reply


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 10:02 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.04790 seconds
  • Memory Usage 2,280KB
  • 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
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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