vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Vbulletin Page Counter (https://vborg.vbsupport.ru/showthread.php?t=50760)

Boofo 03-24-2003 07:17 PM

Vbulletin Page Counter
 
Here is the code I am now using for my page counter on the forumhome. Can anyone please tell me if there is a better way to do this?

PHP Code:

$result mysql_query("SELECT count FROM mycounter");
$mycounter mysql_result($result0) + 1;
$mycounter number_format($mycounter);
$result mysql_query("UPDATE mycounter SET count = count + 1"); 


Zzed 03-25-2003 09:29 PM

You can shuffle them around and reduce them to 3 statements. ;)

But it is not much of a gain anyways. :D

PHP Code:

$result $DB_site->query("UPDATE mycounter SET count = count + 1");
$result $DB_site->query_first("SELECT count FROM mycounter");
$mycounter number_format($mycounter[count]); 


Boofo 03-25-2003 09:36 PM

Since this adds 2 queries, would it be better to write it to a text file and read it from there? Would that save the 2 queries?

Zzed 03-25-2003 09:43 PM

I think with text files you have no way of imposing any kind of mutual exclusion (semaphore). If 1 browser session is writing while the other one is trying to read, or if multiple sessions are trying to update at the same time, they may clubber each other and you can actually lose the counter value in that file.

This won't happen with the query.

colicab-d 03-25-2003 09:44 PM

yeah it would, i would`ve used that from start personally, as iid want to use the extra queries on something a bit more important :P

Zzed 03-25-2003 09:46 PM

The generous use of queries will be ok if forum traffic is not heavy. ;)

Boofo 03-25-2003 09:48 PM

Quote:

Today at 05:29 PM Zzed said this in Post #2
You can shuffle them around and reduce them to 3 statements. ;)

But it is not much of a gain anyways. :D

PHP Code:

$result $DB_site->query("UPDATE mycounter SET count = count + 1");
$result $DB_site->query_first("SELECT count FROM mycounter");
$mycounter number_format($mycounter[count]); 


This didn't work. My counter was at 0 and never increased. ;)

filburt1 03-25-2003 10:48 PM

PHP Code:

$mycounter $DB_site->query_first("SELECT count FROM mycounter");
$DB_site->query("UPDATE mycounter SET count = count + 1");
echo 
$mycounter['count']; 


Boofo 03-26-2003 12:36 AM

Thank you, sir. That worked. ;)


All times are GMT. The time now is 09:20 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.01159 seconds
  • Memory Usage 1,735KB
  • 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
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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