PDA

View Full Version : Vbulletin Page Counter


Boofo
03-24-2003, 07:17 PM
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?

$result = mysql_query("SELECT count FROM mycounter");
$mycounter = mysql_result($result, 0) + 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


$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
Today at 05:29 PM Zzed said this in Post #2 (https://vborg.vbsupport.ru/showthread.php?postid=373285#post373285)
You can shuffle them around and reduce them to 3 statements. ;)

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


$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
$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. ;)