Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> page counter with php+mysql, Another solution for counter
bx93
post Oct 5 2004, 02:55 AM
Post #1


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 68
Joined: 11-September 04
From: Hangzhou, China
Member No.: 488



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.
Go to the top of the page
 
+Quote Post
Loser
post Oct 5 2004, 05:01 PM
Post #2


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 12
Joined: 3-October 04
Member No.: 1,027



I probably sound like a n00b, but I ask why to use MySQL in it?
Go to the top of the page
 
+Quote Post
k22
post Oct 5 2004, 05:22 PM
Post #3


Advanced Member
Group Icon

Group: Members
Posts: 165
Joined: 22-September 04
From: IS - IT - US - BE
Member No.: 804



Not each provider gives a Free-Sql Account sad.gif, Isn't bettere to use a simple page with the number of the visitors?
Go to the top of the page
 
+Quote Post
bx93
post Oct 6 2004, 08:56 AM
Post #4


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 68
Joined: 11-September 04
From: Hangzhou, China
Member No.: 488



QUOTE(k22 @ Oct 6 2004, 01:22 AM)
Not each provider gives a Free-Sql Account sad.gif, Isn't bettere to use a simple page with the number of the visitors?
*



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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. What's The Diff?...php/mysql?(7)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 10:40 PM