Revision [1888]
This is an old revision of GmBowenCounter made by GmBowen on 2004-10-17 20:50:02.
entry into _pages table....
`hits` int(50) NOT NULL default '0'
and the counter.php code....
<? $thispage=$this->GetPageTag(); // Get hit count $result2 = mysql_query( "SELECT hits FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='Y'" ); $row2 = mysql_fetch_array($result2); $hit_count1 = $row2[hits]; // End Get hit Count Start adding hits $hit_count2 = $hit_count1 + 1; // End adding hits Start Update Hit $sql = "UPDATE `".$this->config["table_prefix"]."pages` SET `hits` = '$hit_count2' WHERE tag='$thispage' AND latest='Y'"; // $sql .= " WHERE `ref` = $ref"; mysql_query($sql) or die("Unable to process query: " . mysql_error()); // End Update Hit // End Do not edit // Start output of counter $result4 = mysql_query("SELECT hits FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='Y'"); $row4 = mysql_fetch_array($result4); $hit_count3 = $row4['hits']; echo '<table cellpadding="0" cellspacing="0">'; echo '<tr><td><font face="verdana" size="2"><b>Total Hits:</b></font></td><td><font face="verdana" size="2"> '; print "$hit_count3"; echo '</font></td></tr></table>'; // End Output of counter ?>
If you only use the above code the counter will re-set to zero every time you edit a page (well, 2 actually). If you don't want that to happen you have to do the following changes as well....
In the handlers/edit.php file I added..... $pagehits = $this->page['hits']; on the third line immediately before.... if ($this->HasAccess("write") && $this->HasAccess("read")) and then on around line 35 changed.... $this->SavePage($this->tag, $body, $note); to $this->SavePage($this->tag, $body, $note, $pagehits); AND I learned (through seemingly bizarre but now understandable errors cropping up) that the order of the variables is important relative to the SavePage function (see below....which is why $pagehits doesn't follow the $comment_on variable but precedes it) In the WAKKA.PHP file in the wiki root..... Around line 235, in the SavePage function, the line has to be changed to function SavePage($tag, $body, $note, $pagehits, $comment_on = "") note that $pagehits has to PRECEDE the $comment_on variable a few lines down, the following line has to be added.... "hits = '".mysql_escape_string($pagehits)."', ". I added it after the line.... "user = '".mysql_escape_string($user)."', ".