Recommend this page to a friend! |
Visits | > | All threads | > | rgfpy | > | (Un) Subscribe thread alerts |
|
Robert Galeano Fernandez - 2011-04-16 03:57:13
I adapted to work on php v5.2.14
<?php //Copyright محمد مصطفي شهركي @ http://www.ncis.ir // Modificado para soporte en php 5.2.14 - Robert Galeano Fernandez - $(rgfpy) - www.sourcepy.com class Visits{ private $now; public function Visits(){ $this->Today(); } private function Today(){ //$this->now = new DateTime('now'); $this->now = date('Y-m-d'); } private function Connect(){ mysql_connect('localhost','root',''); mysql_select_db('visits'); mysql_query('SET NAMES \'utf8\''); } public function Count(){ $this->Connect(); $this->Today(); $now = $this->now; //$now = $now->format('Y-m-d'); $result = mysql_query("SELECT * FROM counter WHERE (vdate='$now') ORDER BY id"); switch(mysql_num_rows($result)){ case -1: echo '<P dir="ltr" align="left">'.mysql_error().'</P>'."\n"; break; case 0: $result = mysql_query('SELECT * FROM counter ORDER BY id DESC LIMIT 1'); $id = 0; if(mysql_num_rows($result) > 0){ $id = mysql_result($result, 0, 0); } $id++; mysql_query("INSERT INTO counter VALUES ('$id','$now','1')"); break; default: while($row = mysql_fetch_array($result)){ $id = $row['id']; mysql_query("UPDATE counter SET count=count+1 WHERE (id='$id')"); } break; } } public function GetAll(){ $this->Connect(); $result = mysql_query('SELECT * FROM `counter` ORDER BY `id`'); $visits = 0; if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ $visits += $row['count']; } } return $visits; } public function GetLastDays($days){ $this->Connect(); $this->Today(); $now = $this->now; $result = mysql_query('SELECT * FROM counter ORDER BY id'); $visits = 0; if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ //$vdate = new DateTime($row['vdate']); $vdate = $row['vdate']; $interval = -1; while($vdate <= $now){ //$vdate->add(new DateInterval('P1D')); $vdate = date("Y-m-d", strtotime("$vdate + 1 days")); $interval++; } if($interval < $days){ $visits += $row['count']; } } } return $visits; } public function GetLastDay($day){ $this->Connect(); $this->Today(); $now = $this->now; $result = mysql_query('SELECT * FROM counter ORDER BY id'); $visits = 0; if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ //$vdate = new DateTime($row['vdate']); $vdate = $row['vdate']; $interval = -1; while($vdate <= $now){ //$vdate->add(new DateInterval('P1D')); $vdate = date("Y-m-d", strtotime("$vdate + 1 days")); $interval++; } if($interval == $day){ $visits += $row['count']; } } } return $visits; } public function GetToday(){ $this->Connect(); $this->Today(); $now = $this->now; //$now = $now->format('Y-m-d'); $result = mysql_query("SELECT * FROM counter WHERE (vdate='$now') ORDER BY id"); $visits = 0; if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ $visits += $row['count']; } } return $visits; } } ?> |
info at phpclasses dot org
.