|
|
page counter with php+mysql - Another solution for counter | ||
Discussion by bx93 with 4 Replies.
Last Update: October 6, 2004, 8:56 am | |||
Most counter were realized with files. Here I suggest another solution which use php and mysql.
A file named welcome.php contains the following code:
<?php
function welcome(){
$query= "update webcount set count=count+1;";
mysql_query($query);
$query= "SELECT count FROM webcount;";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
return $row[0];
}
?>
in index.php file,
require the welcome.php at the first place.
<?php
require("welcome.php");
?>
<html>....</html>
show the count:
<?php echo welcome(); ?>
There is some benefit we may get from this solution, though current version support only one counter in the system, but you could easily change it to multi-counter version which could used to count every page in the site or provide counter to the others.
A file named welcome.php contains the following code:
<?php
function welcome(){
$query= "update webcount set count=count+1;";
mysql_query($query);
$query= "SELECT count FROM webcount;";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
return $row[0];
}
?>
in index.php file,
require the welcome.php at the first place.
<?php
require("welcome.php");
?>
<html>....</html>
show the count:
<?php echo welcome(); ?>
There is some benefit we may get from this solution, though current version support only one counter in the system, but you could easily change it to multi-counter version which could used to count every page in the site or provide counter to the others.
Tue Oct 5, 2004 Reply New Discussion
I probably sound like a n00b, but I ask why to use MySQL in it?
Tue Oct 5, 2004 Reply New Discussion
Not each provider gives a Free-Sql Account
, Isn't bettere to use a simple page with the number of the visitors?
Tue Oct 5, 2004 Reply New Discussion
QUOTE (k22)
Not each provider gives a Free-Sql Account
[post="4494"]<{POST_SNAPBACK}>[/post]
Yeah, there is really a little more complex if we want to provide others with MySql counter. When I designing the multi-version counter, I found that every time, there should be database connection and close task, which may not so fast than operations on files. What you mentioned maybe more important is that the counter provider should has the MySql access, thanks astahost.com, but it is difficult to find when hosting at other place.
Anyway, I agree with your suggestion.
Wed Oct 6, 2004 Reply New Discussion
A good website for applying COUNTERS You can make your own counters~^^ (9)
|
(6) CSS Styles
|
Index




